 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 10th, 2007, 08:18 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

January 11th, 2007, 01:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

January 11th, 2007, 01:45 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

January 11th, 2007, 02:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

January 11th, 2007, 04:47 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 11th, 2007, 04:56 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
I would just use:
. I think item is a method so it would be:
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)
|
|

January 11th, 2007, 05:15 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 11th, 2007, 05:44 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|
 |