Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
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
 
Old January 10th, 2007, 08:18 AM
Authorized User
 
Join Date: Mar 2006
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>
 
Old January 11th, 2007, 01:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old January 11th, 2007, 01:45 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
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
 
Old January 11th, 2007, 02:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old January 11th, 2007, 04:47 AM
Authorized User
 
Join Date: Mar 2006
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
 
Old January 11th, 2007, 04:56 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old January 11th, 2007, 05:15 AM
Authorized User
 
Join Date: Mar 2006
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
 
Old January 11th, 2007, 05:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)





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





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