Click to See Complete Forum and Search --> : Table Row Functions ?


gnanesh
07-17-2003, 07:24 AM
folks

I have a table like below

<table>
<tr onClick="javascript:abc();">
<td><input type = checkbox></td>
<td><input type=text name=txt1>abc</td>
<td><input type=text name=txt1>xyz</td>
</tr>
</table>

I need to get the values of all of the 'td' s when the user clicks on that particular row i.e row where in i need to pass all the values to the function which i will call

If any one knows how to do this, kindly let me know , any code is appreciated

Thanks & Regards
GG

AdamBrill
07-17-2003, 07:42 AM
Try this:<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function abc(element){
children = element.childNodes;
for(x=0; x<children.length; x++){
alert(children[x].innerHTML);
}
}
</script>
</head>
<body>
<table>
<tr onClick="javascript:abc(this);">
<td><input type = checkbox></td>
<td><input type=text name=txt1>abc</td>
<td><input type=text name=txt1>xyz</td>
</tr>
</table>
</body>
</html>Let me know if you wanted it different than that... ;)

gnanesh
07-17-2003, 07:51 AM
Adam

Thanks for the code, Here what i did

var children = document.first.element[0].childNodes;
for(x=0; x<children.length; x++){
alert(children[x].innerHTML);
}

where 'first' is my form name and i will not be knowing how many row's the table will return as its get's generated from the backend , finally it will be in Table only, i will be calling a function inside <TR>, I am getting document.first.element.childNodes is null or object

Let me know if i need to change anything on this

Regards
GG

AdamBrill
07-17-2003, 07:59 AM
Try this instead of the other function:function abc(element){
children = element.childNodes;
for(x=0; x<children.length; x++){
test = children[x].getElementsByTagName('input');
for(y=0; y<test.length; y++){
alert(test[y].value);
}
}
}Is that what you want? If not, let me know... ;)

gnanesh
07-17-2003, 08:01 AM
Adam

test = children[x].getElementsByTagName('input');

what i should pass to this method , is the table name or form name ? i.e. replace 'input'

Regards
GG

AdamBrill
07-17-2003, 08:05 AM
"input" shouldn't get replace by anything. It is exactly how it should be. :) Try it and see if you get the desired results. What it is doing is taking all of the <input tags and alerting the value of them all. I think that's what you wanted... ;)

gnanesh
07-17-2003, 08:09 AM
Thanks , thought so

By the way i tried with your piece of function , it says 'element' is undefined at the below line

children = element.childNodes;

even if i call like

children = document.element.childNodes;

it say's null or not an object

Any advice

Regards
GG

AdamBrill
07-17-2003, 08:15 AM
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function abc(element){
children = element.childNodes;
for(x=0; x<children.length; x++){
test = children[x].getElementsByTagName('input');
for(y=0; y<test.length; y++){
alert(test[y].value);
}
}
}
</script>
</head>
<body>
<table>
<tr onClick="java script:abc(this);">
<td><input type = checkbox></td>
<td><input type=text name=txt1>abc</td>
<td><input type=text name=txt1>xyz</td>
</tr>
</table>
</body>
</html>
Try this code and see if it works. You probably forgot to put the "this" inside the function when you were calling it. Also, make sure you delete the space out of the javascript:abc(this), since the forums adds that in there. :)

gnanesh
07-17-2003, 08:34 AM
I have passed 'this' to my function, By the way i am able to get some value 'on' when i called this function, But let me know how do i access the value of each <td>'s

Regards
GG

AdamBrill
07-17-2003, 08:51 AM
Are you trying to get the value of the form elements or the innerHTML of the tds? The one that I just posted will get the values of the form elements...

gnanesh
07-17-2003, 08:56 AM
I am trying to get the values inside <TD>xxx</TD> i.e i need 'xxx' from this tag's , By the way if i do

children = obj.childNodes;
children.length --- i will get 7 as i have 7 Columns , then

if i do like this

test = children[x].getElementsByTagName('td');
alert(test.length);

i passed 'td' instead of 'input' then i am getting the length '0',

Let me know how do i get the values of 'TD'

Regards
Gnanesh

AdamBrill
07-17-2003, 09:30 AM
This(my original post) will get whatever is inside the <td> tags:<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function abc(element){
children = element.childNodes;
for(x=0; x<children.length; x++){
alert(children[x].innerHTML);
}
}
</script>
</head>
<body>
<table>
<tr onClick="javascript:abc(this);">
<td><input type = checkbox></td>
<td><input type=text name=txt1>abc</td>
<td><input type=text name=txt1>xyz</td>
</tr>
</table>
</body>
</html>Remember to take the space out of the the javascript on this line:

<tr onClick="javascript:abc(this);">