473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.sendfo rm."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 3191
Hello Will,

You can access as:

theForm.element s['chk'+id].Method/Property

You can also walk in the elements list as:
for (i=0;i<theForm. elements.length ;i++)
{
e = theForm.element s[i];
if (e.name.substr( 0, 3) == 'chk')
// do something here
}
--
Elias
"Will" <wi*****@ntsols .com> wrote in message
news:8a******** *************** ***@posting.goo gle.com...
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.sendfo rm."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
1407
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 button and an 'add another email' button, which will dynamically (and on the client side) create another text box. How do I implement such a page in JSF? In particular, while the JSP page will contain only 1 text box, the form submission will...
2
12872
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" > Pearl Color: <select name="product1">
27
4749
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 box, I concatenate the selections from the two boxes and add the string to a list at the top of the form, using createElement and appendChild. The list is actually a bunch of span elements contained within a div. Each span element includes a small...
2
4553
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 Function LayoutForm(ByVal intNumber As Integer) Dim intCount As Integer Panel1.Controls.Clear() For intCount = 1 To intGames
1
1463
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" name="text_3" ...> <input type="select" name="text_4" ...> </form> And I doing some validation like this.
4
2713
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 multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
3
5844
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() themeIDField.ID = "theme_id" themeNamePlaceholder.Controls.Add(themeIDField) End sub ....and call this at page_load. I now need to get the name value pairs of these fields to submit to a DB procedure. I've tried using
2
2212
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 label is from a table The code I have written so far is protected void Page_Load(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("select * from Categories", cnn); SqlDataReader dr;
2
4051
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 dynamic text boxes are created and if user selects 4 then 4 dynamic text boxes are created and so on. Here is the code I am using to dynamically create the text boxes: echo ("<form name='exam' action='exam_2.php' method='POST'>"); for...
0
8917
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9142
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4525
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.