473,387 Members | 1,569 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,387 software developers and data experts.

Naming Dynamic Input Boxes

The following will add an input box on submit everytime a button is clicked. I would like it so that it names the input box differently everytime it is added starting with the number2, for example Student_Firstname2, Student_Firstname3, Student_Firstname4, etc.

Expand|Select|Wrap|Line Numbers
  1.  <input name="add_students" type="button" class="submit" onClick="add_student()" value="Add More Students">
  2.  
  3.  
  4. function add_student(){
  5.  
  6. //// Create Labels ////
  7. var label = document.createElement("label");
  8.  
  9. //// Create text ////
  10. var firstname_text = document.createTextNode("First Name: ");
  11.  
  12. //// Create input boxes ////
  13. var StudentFirstname=document.createElement('input') ;
  14. StudentFirstname.type='text';
  15. StudentFirstname.size='45';
  16. StudentFirstname.name='Student_Firstname';
  17.  
  18. //// Append ////
  19. label.appendChild(firstname_text);
  20. document.forms.Registration.appendChild(label);
  21. document.forms.Registration.appendChild(StudentFirstname);
  22. }
  23.  
Jul 20 '07 #1
5 2031
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. var keep_track=1;
  2. function add_student(){
  3. keep_track++;
  4.  
  5. //// Create Labels ////
  6. var label = document.createElement("label");
  7.  
  8. //// Create text ////
  9. var firstname_text = document.createTextNode("First Name: ");
  10.  
  11. //// Create input boxes ////
  12. var StudentFirstname=document.createElement('input') ;
  13. StudentFirstname.type='text';
  14. StudentFirstname.size='45';
  15. StudentFirstname.name='Student_Firstname'+keep_track;
  16.  
  17. //// Append ////
  18. label.appendChild(firstname_text);
  19. document.forms.Registration.appendChild(label);
  20. document.forms.Registration.appendChild(StudentFirstname);
  21. }
  22.  
Jul 20 '07 #2
Excellent. Thank you!

Is there anyway to get it to print Student3_Firstname instead of like this: Student_Firstname3.
Jul 20 '07 #3
pbmods
5,821 Expert 4TB
Heya, Nitestarz.

Expand|Select|Wrap|Line Numbers
  1. 'Student' + keep_track + '_Firstname'
  2.  
Jul 21 '07 #4
kovik
1,044 Expert 1GB
I'd suggest that you just use HTML arrays. It's more organized, and can be easily used upon posting.
Jul 21 '07 #5
Thank you! Works beautifully! :-)
Jul 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: pizzy | last post by:
PROBLEM: I CAN'T GET THE LAST RESUTS TO WORK CORRECTLY. I WOULD PROVIDE THE CODE (AND WILL IF REQUESTED). BUT IN MY OWN WORDS I AM TRYING TO HAVE THE FIRST FORM DYNAMICALLY CREATE INPUT BOXES...
2
by: Ian Vincent | last post by:
I am hoping someone may be able to help. I am using Python and TKinter to create a GUI program that will eventually create an XML file for a project I am working on. Now, the XML file contents...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
8
by: Jason | last post by:
In my ASP.NET 1.1 solutions, I created several web projects and compiled them each into an assembly. The assembly names reflected the functionality of the feature (Membership.dll, Dues.dll, etc)....
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
3
by: markbpriv | last post by:
Hi, I was wondering if you can help. I am trying to create a spreadsheet like form in asp.net that is dynamically created. I am using VB.net in Visual Web Developer Express Edition 2008. ...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
4
by: sidesteal | last post by:
PLEASE forgive me! I have been a web designer for a few years now, and want to move on and learn a programming language. Im currently building a website, and i have a js file that contains some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.