472,371 Members | 1,351 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,371 software developers and data experts.

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 3097
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ittay Dror | last post by:
Hi, As an example, imagine I want to write a page with a form for emailing it to a number of people. In pure HTML, i'd create an initial layout of one text box (for entering an email), a submit...
2
by: juglesh | last post by:
hi, all, thanks for reading. i have a form in which i want drop down boxes to dynamically change some hidden fields: http://cynthialoganjewelry.com/test4.htm <form name=test method="post" > ...
27
by: Nicholas Couch | last post by:
I have a little form with a couple of dynamically generated list boxes. When the user makes a selection from the first box, the second box is refreshed. When they make a selection from the second...
2
by: D Hass | last post by:
Radio Buttons are added to my form During the Load event, the quantity determined by User input. They are placed in pairs on groupboxes with code like this: (edited a bit for brevity) Public...
1
by: sam | last post by:
I have form elements which dynamically generated like this... <form name="formA" ...> <input type="select" name="text_1" ...> <input type="select" name="text_2" ...> <input type="select"...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
3
by: guido | last post by:
I've written a user control to add form fields to a aspx page: Private Sub buildFields() 'Label1.Text = "building fields at " & System.DateTime.Now() Dim themeIDField As New TextBox()...
2
by: savianand | last post by:
I want to know the code how to save data from dynamically created textboxes. The code I have written is this in whch I have dynamically created label and textboxes in a html table.The data in the...
2
by: gubbachchi | last post by:
Hi, I have a form whose elements are created dynamically on selection, i.e. the form has only text boxes and the number of text boxes depends on the users selection, if user selects 3 then 3...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.