473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

find form elements in particular TableRow

Hi, As you can see from the code below I have a simple js function
called getFormElementsinTableRow(rowName). rowName is the ID of the
tableRow. I just want to use js to find the child ID's of all the form
elements in that particular tableRow. What am I doing wrong?
<table><tr id="where12" style="DISPLAY:none">
<td><select name="parameter12" id="parameter12">
<option value="1">casenumber</option>
<option value="2">analyst</option>
</select>
<div class='button'>
<A href='#' onclick="javascript:getFormElementsinTableRow
('where12');"> DELETE ROW </A>
<div></td></tr></table>

<Script jang=javascript>
function getFormElementsinTableRow(rowName){

var nodeList = document.getElementById(rowName);

for (var i = 0; i < nodeList.length; i++)
{
var node = nodeList[i];
alert(node.id);
}

}
<script>

Jul 23 '05 #1
2 6576
th*****************@yahoo.com wrote:
Hi, As you can see from the code below I have a simple js function
called getFormElementsinTableRow(rowName). rowName is the ID of the
tableRow. I just want to use js to find the child ID's of all the form
elements in that particular tableRow. What am I doing wrong?
<table><tr id="where12" style="DISPLAY:none">
<td><select name="parameter12" id="parameter12">
<option value="1">casenumber</option>
<option value="2">analyst</option>
</select>
<div class='button'>
<A href='#' onclick="javascript:getFormElementsinTableRow
('where12');"> DELETE ROW </A>
There is no need for the javascript pseudo-protocol, and your onclick
should return false to stop browsers from going back to the top of the
page.

<A href='#' onclick="
getFormElementsinTableRow('where12');
return false;
"> DELETE ROW </A>

Even better would be to not subvert an A element and use something more
suitable - span, div, input type=button, button, etc.
<div></td></tr></table>
^-- Closing tag?

</div>...

<Script jang=javascript>
I'll assume that is a copy/paste error. The 'lang' attribute never
existed for script elements, there is a depreciated 'language'
attribute, but type is required:

<script type="text/javascript">
function getFormElementsinTableRow(rowName){

var nodeList = document.getElementById(rowName);
getElementById() returns a reference to an element. In this case,
'nodeList' will be a reference to the TR element - it is not an array
or collection. nodeList.length will be 'undefined'.

Using what are (to me) more suitable variable names:

function getFormElementsinTableRow( rowID ){
var r = document.getElementById(rowID);
var rA = r.getElementsByTagName('*');

for (var i = 0; i < nodeList.length; i++)
{
var node = nodeList[i];
alert(node.id);
}
Here is an alternative that shows the elements and their ID if they
have one:

var x, i=0;
while ( x = rA[i++] ) {
alert( x.nodeName + '\n' +
((x.id)? 'id: ' + x.id : ' no ID'));
}
}
<script>
Closing tag?

</script>


If you want just the form elements, you'll have to sift through the
collection in rA. If this is for more than casual interest, you should
feature test getElementById and getElementsByTagName before using
them and you may also want to add support for document.all.

Here's the full script:

<script type="text/javascript">

function getFormElementsinTableRow( rowID ){
var r = document.getElementById( rowID )
var rA = r.getElementsByTagName('*');
var x, i=0;

while ( x = rA[i++] ) {
alert( x.nodeName + '\n' +
((x.id)? 'id: ' + x.id : 'no ID') );
}
}
</script>
--
Rob
Jul 23 '05 #2
Thanks Rob for working through my assored typos and brain farts. It
works beautifully now.

Jul 23 '05 #3

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

Similar topics

8
by: Stan Brown | last post by:
http://oakroadsystems.com/nonce/zonk.htm (12 lines) >...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I donīt know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
4
by: Jeremy Ames | last post by:
I have a problem with one of connections using the wrong connection string. I have a form that has three late bound sql connections. Each connection is local to the function that it used in. The...
3
by: Jeremy Ames | last post by:
Can someone please help with this? Unfortunately, that did not work. "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message...
6
by: hb | last post by:
Hi, I have a page bill.aspx and its code-behind bill.aspx.cs. On bill.aspx I have: === Select a month: <asp:dropdownlist runat="server" id="lstDate" autopostback="True" /> <br> <asp:table...
2
by: Michael | last post by:
Need some help trying to read values from web controls - specifically *finding* the controls (like a drop down list) - that are added dynamically added within an asp:panel control. The page...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
4
by: SteveKlett | last post by:
I have a subset of form items that I need to perform different operations on (enable/disable, clear values, change style, etc) rather than hard code the IDs or names I would like to recursively...
2
by: prao2005 | last post by:
My XML Code <DBE:Attribute name="Test1" type="Table"> <DBE:Table> <DBE:TableHeader> <DBE:TableColumn>t1</DBE:TableColumn> ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.