Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 10th, 2007, 08:18 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting Data from a table

Hi,
Is there any way to select data from a table using Javascript..? I understand that it will be a huge code so even if someone gives pointers to some online resource, its very much welcome too ..

------------------------------------------------------------------------------------------------------------
Adventure, Play, Alive, Fast, Race, Addict, React, Attack, Heat, Aggression, Blast, Ahead, Escape, Challenge, Anarchy, Game, Real, Damage, Insane, Acclerate,Passion, Fear, Dominate, Crazy, Awesome, Sweat, Habit, Avenge, Balls, Imagine, Viril, Chaos, Amuse, Heavy, Panic, @#!%, Fanatic
__________________
------------------------------------------------------------------------------------------------------------
<b><i>Adventure, Play, Alive, Fast, Race, Addict, React, Attack, Heat, Aggression, Blast, Ahead, Escape, Challenge, Anarchy, Game, Real, Damage, Insane, Acclerate,Passion, Fear, Dominate, Crazy, Awesome, Sweat, Habit, Avenge, Balls, Imagine, Viril, Chaos, Amuse, Heavy, Panic, @#!%, Fanatic </i></b>
Reply With Quote
  #2 (permalink)  
Old January 11th, 2007, 01:41 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Who can say, your question is too vague?
You can use JavaScript to open a connection to a table in a database using ADO, if the database supports OleDb. Or do you you mean accessing data from an HTML table in a web page?

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old January 11th, 2007, 01:45 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 481
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

hi nkrust,
You can connect with javascript but it is not feasible.
You better use ajax for reading data from database but server site languages should use for database connection,

surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
Reply With Quote
  #4 (permalink)  
Old January 11th, 2007, 02:21 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by surendran


You can connect with javascript but it is not feasible.

surendran
I disagree, pre-ASP.NET I always used JavaScript for ASP.
If you mean that connecting via client-side code is impractical then you're right but that's entirely different.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old January 11th, 2007, 04:47 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually I'm selecting multiple rows of a table using javascript, (I know that a listbox is the proper way to do it but with ListBox u cant customise the look). The Problem that i'm facing is that i cant get the values out of the selected fields. The code that i'm using to select(or rather highlight) the rows is:
Code:
function lockRow() {
    var tbodies = document.getElementsByTagName("tbody");
    for (var j=0; j<tbodies.length; j++) {
        var rows = tbodies[j].getElementsByTagName("tr");
        var cell = tbodies[j].getElementsByTagName("td");
        for (var i=0; i<rows.length; i++) {
            rows[i].oldClassName = rows[i].className
            rows[i].onclick = function() {
                if (this.className.indexOf("selected") != -1) {
                    this.className = this.oldClassName;
                } else {
                var text = setDataType(cell.item[i].innerText);
                    addClass(this,"selected");
                }
            }
        }
    }
}
The line in Red is where i'm trying to get the value of the selected cell, unfortunately addition of this line actually fails the code(i mean the rows don't get selected) ...

------------------------------------------------------------------------------------------------------------
Adventure, Play, Alive, Fast, Race, Addict, React, Attack, Heat, Aggression, Blast, Ahead, Escape, Challenge, Anarchy, Game, Real, Damage, Insane, Acclerate,Passion, Fear, Dominate, Crazy, Awesome, Sweat, Habit, Avenge, Balls, Imagine, Viril, Chaos, Amuse, Heavy, Panic, @#!%, Fanatic
Reply With Quote
  #6 (permalink)  
Old January 11th, 2007, 04:56 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would just use:
Code:
cell[i].innerText
. I think item is a method so it would be:
Code:
cell.item(i)
If I rememeber correctly innerText is IE only so innerHTML maybe better.
But do you mean you can't get the text or that the row doesn't get selected? I'm still not sure what the problem is.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #7 (permalink)  
Old January 11th, 2007, 05:15 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After i added the line coded in red, the rows just stopped getting selected.
If instead of cell.item[i] i use cell.item("0") or ("1") the 1st or the 2nd row value is copied to the var text.
So i suppose there's some mistake in that line, or may b its just not possible to do it... I hope i was able to make it clear to u ..

------------------------------------------------------------------------------------------------------------
Adventure, Play, Alive, Fast, Race, Addict, React, Attack, Heat, Aggression, Blast, Ahead, Escape, Challenge, Anarchy, Game, Real, Damage, Insane, Acclerate,Passion, Fear, Dominate, Crazy, Awesome, Sweat, Habit, Avenge, Balls, Imagine, Viril, Chaos, Amuse, Heavy, Panic, @#!%, Fanatic
Reply With Quote
  #8 (permalink)  
Old January 11th, 2007, 05:44 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

But you are storing the oldClassName outside of the onclick function so that might be the reason. As you didn't show setDataType, which seems oddly named, I can't tell.
Do you just want to change the className when the td is clicked? If so it might be easier just to use the onclick of the table itself and then analyse the event object to see which td was clicked rather than having an onclick for all cells.

--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting emails by domain (TLD) from MySQL table? hman MySQL 2 January 11th, 2008 04:32 PM
Chapter 6 Selecting Data in Access ,, Help Me zaidqais BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 May 5th, 2006 03:48 AM
Selecting a table name ... quite hard !!! SKE Classic ASP Databases 0 May 16th, 2005 06:23 AM
Selecting Data.. NitinJoshi General .NET 3 January 18th, 2005 02:59 AM
Selecting and Making a table gmoney060 Classic ASP Databases 4 August 19th, 2004 10:06 AM



All times are GMT -4. The time now is 04:15 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.