943,939 Members | Top Members by Rank

Ad:
Feb 1st, 2007
0

Extending HTML Forms

Expand Post »
I am trying to create an HTML form in which user will enter different items (he wants to purchase) in text fields. One text field is used for one item. Now it is not known in advance how much items the user will purchase so we cannot decide the total text fields required in advance. Is is possible to increase the number of text fields (using JavaScript) one by one if the user requires more fields.
Bye
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
md_salman is offline Offline
12 posts
since Sep 2005
Feb 1st, 2007
0

Re: Extending HTML Forms

Yes is the answer, this should get you started a very very basic solution but enough to show you what you need to be looking at to acheive your goal. check out http://www.w3schools.com

and get yourself a copy of the javascript anthology published by sitepoint ISBN 0-9752402-6-9

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var instance = 0;
  5.  
  6. function newTextBox(element)
  7. {
  8. instance++;
  9. var newInput = document.createElement("INPUT");
  10. newInput.id = "text" + instance;
  11. newInput.name = "text" + instance;
  12. newInput.type = "text";
  13. document.body.insertBefore(newInput, element);
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <input type="button" id="btnAdd" value="New text box" onclick="newTextBox(this);" />
  19. </body>
  20. </html>
Last edited by hollystyles; Feb 1st, 2007 at 9:51 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Nov 9th, 2007
0

Re: Extending HTML Forms

Hello,

the script is exactly what I was searching but I still have a problem.
How can I get the information that people wrote in the text field ? I've tried to put into a <form> but get an error msg.

Can you help ?

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yasminou is offline Offline
1 posts
since Nov 2007
Nov 9th, 2007
0

Re: Extending HTML Forms

Only if you tell me what the error message is, and post your current code in code tags. I don;t know how crystal balls work unfortunately

1. what is the action attribute set to in your form tag?
2. What server-side technology are you using? CGI ? ASP? ASP.NET? PHP? all have their different methods for retreiving the POST data from a submitted HTML Form.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
May 25th, 2011
0
Re: Extending HTML Forms
I've done this base on your instructions and modifications. It works. But once I add the <div> tags, then it stops working. Any way around this?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var instance = 1;
  5.  
  6. function newUpload()
  7. {
  8. instance++;
  9. var newInput = document.createElement("INPUT");
  10. newInput.size = "12";
  11. newInput.name = "regPictures" + instance;
  12. newInput.type = "file";
  13. newInput.style.display = 'block';
  14. element = document.getElementById("btnAdd");
  15. document.getElementById("he").insertBefore(newInput, element);
  16. }
  17. </script>
  18. </head>
  19. <body>
  20. <form id="he">
  21. <div>
  22. <input name="regPictures1" type="file" size="12"/>
  23.  
  24. <br/>
  25. <input type="button" id="btnAdd" value="More" onclick="newUpload();" />
  26. </div>
  27. </form>
  28. </body>
  29. </html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zenghoong is offline Offline
2 posts
since May 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Image Above Div Z-index
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Calling Airshow- Return false; and Z-index issues





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC