469,622 Members | 2,159 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,622 developers. It's quick & easy.

Access dynamically created Form elements

Hi, I have a problem trying to validate dynamically created html form
elements using javascript. I have dynamically created a check box
using ASP for each record in a recordset and have given each a unique
ID using the primary key from a db table. e.g "chk" + "1" for record 1
and "chk" + "2" for record 2 etc. This means each box is called chk1
and chk2 respectively. This works fine and changes dependant on the
recordset used and allows me to pass details to another page for
processing.

However I want to validate each checkbox to check if it is clicked or
not when a submit button is pressed. I cannot work out how to refer to
the elements in the javascript as they have diferent ids every time
the page is created. If I pass in the ID of the check box to the
javascript function is there a way I can concatenate the id to the
prefix "chk" and refer to the element in the form. This may sound
confusing it is to me! Basically every check box on the page is called
"chk" then is suffixed by the id of the record. Now in the javascript
I wish to refer to each checkbox in this sort of manner

document.sendform."chk" + recordID

I have tried this and it didnt seem to work so if anyone has any ideas
it would be much appreciated.

Cheers
Will
Jul 20 '05 #1
1 2985
Hello Will,

You can access as:

theForm.elements['chk'+id].Method/Property

You can also walk in the elements list as:
for (i=0;i<theForm.elements.length;i++)
{
e = theForm.elements[i];
if (e.name.substr(0, 3) == 'chk')
// do something here
}
--
Elias
"Will" <wi*****@ntsols.com> wrote in message
news:8a**************************@posting.google.c om...
Hi, I have a problem trying to validate dynamically created html form
elements using javascript. I have dynamically created a check box
using ASP for each record in a recordset and have given each a unique
ID using the primary key from a db table. e.g "chk" + "1" for record 1
and "chk" + "2" for record 2 etc. This means each box is called chk1
and chk2 respectively. This works fine and changes dependant on the
recordset used and allows me to pass details to another page for
processing.

However I want to validate each checkbox to check if it is clicked or
not when a submit button is pressed. I cannot work out how to refer to
the elements in the javascript as they have diferent ids every time
the page is created. If I pass in the ID of the check box to the
javascript function is there a way I can concatenate the id to the
prefix "chk" and refer to the element in the form. This may sound
confusing it is to me! Basically every check box on the page is called
"chk" then is suffixed by the id of the record. Now in the javascript
I wish to refer to each checkbox in this sort of manner

document.sendform."chk" + recordID

I have tried this and it didnt seem to work so if anyone has any ideas
it would be much appreciated.

Cheers
Will

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ittay Dror | last post: by
2 posts views Thread by juglesh | last post: by
27 posts views Thread by Nicholas Couch | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.