Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Access dynamically created Form elements (http://www.velocityreviews.com/forums/t875366-access-dynamically-created-form-elements.html)

Will 01-23-2004 12:11 PM

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

lallous 01-23-2004 12:20 PM

Re: Access dynamically created Form elements
 
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" <william@ntsols.com> wrote in message
news:8a45f8d9.0401230411.7fb0f900@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





All times are GMT. The time now is 02:35 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.