473,585 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5772
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.eleme nts.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.get ElementById) {
row = document.getEle mentById('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.eleme nts.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.get ElementById) {
row = document.getEle mentById('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.eleme nts.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.get ElementById) {
row = document.getEle mentById('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="JavaS cript" type="text/javascript">
function getOther(sel,fl d){
if (sel.selectedIn dex==sel.option s.length-1) fld.disabled=fa lse; else
fld.disabled=tr ue;
var row1 = null;
var row2 = null;
var row3 = null;

if(document.get ElementById) {
row1 = document.getEle mentById('id1') ;
row2 = document.getEle mentById('id2') ;
row3 = document.getEle mentById('id3') ;
}
if(row1) {
row1.style.disp lay =
(sel.selectedIn dex==sel.option s.length-1)?"inline":"no ne";
}
if(row2) {
row2.style.disp lay =
(sel.selectedIn dex==sel.option s.length-1)?"inline":"no ne";
}
if(row3) {
row3.style.disp lay =
(sel.selectedIn dex==sel.option s.length-1)?"inline":"no ne";
}
}
</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">Podatk i o
plačniku</font></b></td>
<td width="177"><fo nt face="Verdana"> <select size="1" name="D1"
onchange="getOt her(this,this.f orm.naziv);getO ther(this,this. form.sedez);get Other(this,this .form.davcna);" >
<option selected value="sam">sam oplačnik</option>
<option value="podjetje ">podjetje</option>
</select></font></td>
</tr>
<tr id="id1" style="display: none;">
<td width="177">Naz iv:</td>
<td width="177"><fo nt face="Verdana">
<input type="text" name="naziv" size="20" disabled></font></td>
</tr>
<tr id="id2" style="display: none;">
<td width="177">Sed e<span lang="sl">ž</span></td>
<td width="177"><fo nt 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"><fo nt 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.selectedInd ex == sel.options.len gth - 1;
fld.disabled = !lastOpt;
if (document.getEl ementById) {
var rows = [
document.getEle mentById('id1') ,
document.getEle mentById('id2') ,
document.getEle mentById('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.selectedInd ex == sel.options.len gth - 1;
fld.disabled = !lastOpt;
if (document.getEl ementById) {
var rows = [
document.getEle mentById('id1') ,
document.getEle mentById('id2') ,
document.getEle mentById('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
3656
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 row, but it adds a <TR></TR> pair just before the </TBODY> and that leaves the tbody.rows.length count unchanged.
7
2111
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
7232
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 this only gives me table rows with no table data cells. So I would like to know if it's possible to create several <TH> within the tHead row using...
4
5824
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 my purpose. Can you suggest any free or inexpensive HTML that can do that? Thanks Dominic
1
2214
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 pages "as is" in the new 2.0 app without using Master Pages or creating new ..aspx's. I'm looking for the quickest way to the finish line. Any...
2
2672
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
2931
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 Accessories
3
1714
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 table which contains a data is under div which has a scroll bar.. What in trying to do is freeze the first row of the table which is been generated.....
7
2776
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. $test=~/<tr><td>(.*)<\/td><\/td>(.*)<\/td><\/tr>/ms; <tr><td>station</td> <td>station number/identification, see chart above: <br> B = GoMoos buoy B location<br> S...
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.