472,954 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

referencing a <tr> object

Hi,

if i have this code: <form><input type=text name="id1"></form> then with
javascript i can reference this with this.form.id1, how can i reference
something like this:

<table>
<tr name="id2">
..
..
</table>

?

this.id2 doesn't work

thank you,
Greg
Jul 23 '05 #1
5 5736
Gregor Rot wrote:
if i have this code: <form><input type=text name="id1"></form> then with
javascript i can reference this with this.form.id1 [...]
That works because form controls with name and id attributes are usually
made available as properties of a FORM element. However, I think it's
preferable to use the elements collection to reference form controls:

this.form.elements.id1

The shorthand form was, in my opinion, a mistake and the elements
collection is standardised.
how can i reference something like this:

<table>
<tr name="id2">


You shouldn't be able to. Table rows, like the vast majority of
elements, do not have name attributes. They do have id attributes,
though. You can then use the getElementById method to obtain a reference:

<tr id="id2">
var row = null;

if(document.getElementById) {
row = document.getElementById('id2');
}
if(row) {
/* Now have a reference to the table row. */
}

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Michael Winter wrote:
Gregor Rot wrote:
if i have this code: <form><input type=text name="id1"></form> then
with javascript i can reference this with this.form.id1 [...]

That works because form controls with name and id attributes are usually
made available as properties of a FORM element. However, I think it's
preferable to use the elements collection to reference form controls:

this.form.elements.id1

The shorthand form was, in my opinion, a mistake and the elements
collection is standardised.
how can i reference something like this:

<table>
<tr name="id2">

You shouldn't be able to. Table rows, like the vast majority of
elements, do not have name attributes. They do have id attributes,
though. You can then use the getElementById method to obtain a reference:

<tr id="id2">
var row = null;

if(document.getElementById) {
row = document.getElementById('id2');
}
if(row) {
/* Now have a reference to the table row. */
}

[snip]

Hope that helps,
Mike

Thank you, it works nicely.

by,
Greg
Jul 23 '05 #3
Gregor Rot wrote:
Michael Winter wrote:
Gregor Rot wrote:
if i have this code: <form><input type=text name="id1"></form> then
with javascript i can reference this with this.form.id1 [...]


That works because form controls with name and id attributes are
usually made available as properties of a FORM element. However, I
think it's preferable to use the elements collection to reference form
controls:

this.form.elements.id1

The shorthand form was, in my opinion, a mistake and the elements
collection is standardised.
how can i reference something like this:

<table>
<tr name="id2">


You shouldn't be able to. Table rows, like the vast majority of
elements, do not have name attributes. They do have id attributes,
though. You can then use the getElementById method to obtain a reference:

<tr id="id2">
var row = null;

if(document.getElementById) {
row = document.getElementById('id2');
}
if(row) {
/* Now have a reference to the table row. */
}

[snip]

Hope that helps,
Mike

Thank you, it works nicely.

by,
Greg


The problem is that in Mozilla the rows when appearing/disappearing
display strangely, and making more and more space ... strange. Any
experience with that? (in IE it works fine)

I am attaching you the full code so somebody can check - the text at the
end of the page when sqitching the scrollbar gets more and more pushed
down the page...

tnx,
Greg

<html>
<head>
<script language="JavaScript" type="text/javascript">
function getOther(sel,fld){
if (sel.selectedIndex==sel.options.length-1) fld.disabled=false; else
fld.disabled=true;
var row1 = null;
var row2 = null;
var row3 = null;

if(document.getElementById) {
row1 = document.getElementById('id1');
row2 = document.getElementById('id2');
row3 = document.getElementById('id3');
}
if(row1) {
row1.style.display =
(sel.selectedIndex==sel.options.length-1)?"inline":"none";
}
if(row2) {
row2.style.display =
(sel.selectedIndex==sel.options.length-1)?"inline":"none";
}
if(row3) {
row3.style.display =
(sel.selectedIndex==sel.options.length-1)?"inline":"none";
}
}
</script>
</head>

<body>
<form action="">
<div align="center">
<table border="0" name="tb" id="tb" width="364">
<tr>
<td width="177"><b><font face="Verdana" size="2">Podatki o
plačniku</font></b></td>
<td width="177"><font face="Verdana"><select size="1" name="D1"
onchange="getOther(this,this.form.naziv);getOther( this,this.form.sedez);getOther(this,this.form.davc na);">
<option selected value="sam">samoplačnik</option>
<option value="podjetje">podjetje</option>
</select></font></td>
</tr>
<tr id="id1" style="display: none;">
<td width="177">Naziv:</td>
<td width="177"><font face="Verdana">
<input type="text" name="naziv" size="20" disabled></font></td>
</tr>
<tr id="id2" style="display: none;">
<td width="177">Sede<span lang="sl">ž</span></td>
<td width="177"><font face="Verdana">
<input type="text" name="sedez" size="20" disabled></font></td>
</tr>
<tr id="id3" style="display: none;">
<td width="177">Davčna številka</td>
<td width="177"><font face="Verdana">
<input type="text" name="davcna" size="20" disabled></font></td>
</tr>
</table>
</div>
<p align="center">some other text</p>
</form>
</body>

</html>
Jul 23 '05 #4
Gregor Rot wrote:
The problem is that in Mozilla the rows when appearing/disappearing
display strangely, and making more and more space ... strange. Any
experience with that? (in IE it works fine)


Assign "", not "inline", to the display property to fix that.

Some more changes I suggest for your script:

function getOther(sel, fld) {
var lastOpt = sel.selectedIndex == sel.options.length - 1;
fld.disabled = !lastOpt;
if (document.getElementById) {
var rows = [
document.getElementById('id1'),
document.getElementById('id2'),
document.getElementById('id3')
];
var disp = lastOpt? "" : "none";
for (var i=0; i<rows.length; i++) {
if (rows[i] && rows[i].style) {
rows[i].style.display = disp;
}
}
}
}

ciao, dhgm
Jul 23 '05 #5
Dietmar Meier wrote:
Gregor Rot wrote:
The problem is that in Mozilla the rows when appearing/disappearing
display strangely, and making more and more space ... strange. Any
experience with that? (in IE it works fine)

Assign "", not "inline", to the display property to fix that.

Some more changes I suggest for your script:

function getOther(sel, fld) {
var lastOpt = sel.selectedIndex == sel.options.length - 1;
fld.disabled = !lastOpt;
if (document.getElementById) {
var rows = [
document.getElementById('id1'),
document.getElementById('id2'),
document.getElementById('id3')
];
var disp = lastOpt? "" : "none";
for (var i=0; i<rows.length; i++) {
if (rows[i] && rows[i].style) {
rows[i].style.display = disp;
}
}
}
}

ciao, dhgm

TNX, it works fine now.

Greg
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Geddes | last post by:
In both IE6 and Netscape 7: insertRow method of tbody is behaving as expected: - inserts a new row - increases tbody.rows.length BUT deleteRow is not doing the opposite. It DOES delete the...
7
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
4
by: El Diablo | last post by:
Hi there, I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment: theTable.tHead.appendChild(document.createElement('TR')) ....but...
4
by: Dominic | last post by:
I'm looking for a HTML editor that can match the opening and closing HTML tags such as <TR> </TR>, <TD> </TD> I think Dreamweaver does that, right? Even if it does, it may be too expensive for...
1
by: prefersgolfing | last post by:
I'm not using Master Pages, yet I'd like to display the contents of an HTML page within a <table><tr><td> on a .aspx. I have a lengthy guide already paginated in html. I'd like to embed the...
2
by: petereffect | last post by:
i have foll. code <tr> <a href="a1.shtml"> <td width='100%'> &nbsp;"+Testing+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td> </a>
5
by: mahesr | last post by:
I want to match some particular text between <tr>and </tr> or <td>and </td>.... in PHP. like below............ <table><tr> CATEGORY: <td><font face="Verdana" size="1" color="#A000A0"> Wedding...
3
by: jack | last post by:
Hi all im Creating a report in HTML with the help of dotnet.. im creating a which shows a data of 12 months .. the forst row of the column contains month names.. and the following data.. The...
7
by: Xiaoyan | last post by:
Hi,everyone: I have a problem now. I can't get the information between the <tr><td> and </td></tr>. for example: I use this regular expression can't get it, I don't know why....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.