HOW to get the parent of text field in a table

S

Sergio Otoya

Hi all,

I need to access the <TR> element where an input text field is hosted.
I would like to do this client side as i need to hide the TR based on
certain conditions.

The HTML is already written and cannot get to the source because it is
a server side page that we don't have acess to, but we can include
certain javascript snippets.

So the HTML looks something like this by the time i can execute my
javascript function:

<TABLE>
<TR>
<TH nowrap valign="top" class="ms-formlabel"><nobr>Name<font
color="red"> *</font></nobr></TH>
<TD class="ms-formbody"><INPUT TYPE="text" NAME="somefield"
id="idFilename" >
</TD>
</TR>
....

</TABLE>


So the element that i can get to is idFilename but need to hide the
whole TR row based on certain conditions.

Question: is it possible to do that?. can I use some sort of
parentNode or container method to get to the TR?

I would greatly appreciate any help.

thanks in advance.

Sergio
 
M

Michael Winter

I need to access the <TR> element where an input text field is hosted.
[snip]

Question: is it possible to do that?. can I use some sort of parentNode
or container method to get to the TR?

Yes, use the parentNode property:

var cell, row;

if((cell = inputRef.parentNode) && (row = cell.parentNode)) {
// row now refers to the parent row of the element, inputRef
}

The best way to get inputRef depends upon how the code is called.

[snip]

Hope that helps,
Mike
 
S

Sergio Otoya

Mike,

Thanks very much for your response. It works perfectly.

Sergio.

Michael Winter said:
I need to access the <TR> element where an input text field is hosted.
[snip]

Question: is it possible to do that?. can I use some sort of parentNode
or container method to get to the TR?

Yes, use the parentNode property:

var cell, row;

if((cell = inputRef.parentNode) && (row = cell.parentNode)) {
// row now refers to the parent row of the element, inputRef
}

The best way to get inputRef depends upon how the code is called.

[snip]

Hope that helps,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top