Click to See Complete Forum and Search --> : retrieving <TD> values that have no <INPUT>


nanditasr
06-30-2003, 01:13 AM
I have a table with <TD> tags, but not necessarily an <input> tag between the <TD> and </TD> tags .
Using JavaScript, is there any way I can I retrieve the value in the TD tag? (Of course, I can create an <input> with an invisible border, and get this value easily, but then I am unnecessarily creating another field. I have to do this at several places and then post the form, so I am not too keen on creating so many fields.)

Example:

<FORM name=myForm><TABLE>
<TR><TD>Name</TD><TD id=Row1Col2>John</TD></TR>
<TR><TD>Age</TD><TD><INPUT id=ageTx></TD></TR>
</TABLE></FORM>

Now, in JavaScript, I can get the age by saying :

document.myForm.ageTx.value;

but I cannot get "John" by saying:

document.myForm.Row1Col2.value OR document.myForm.Row1Col2.text

Any suggestions?

Thanks,
Nandita

JHL
06-30-2003, 02:06 AM
document.getElementById('Row1Col2').innerHTML

nanditasr
06-30-2003, 04:06 AM
Thanks, JHL; this works.