By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 IT Pros & Developers. It's quick & easy.

Add more text fields to existing text fields.

P: 44
Beginner javascipt/vbscript.

I hava a form, which has five lines to enter at start. I want to have a button to add more lines when it is clicked. However, I am having trouble with it. This is written in vbscipt and ADO.

Expand|Select|Wrap|Line Numbers
  1. Code: ( text )
  2. <%
  3. Const linesNo = 5
  4. Dim counter
  5.  
  6. <html>
  7. .....
  8.  
  9. <form action='return_form.asp' method=post>
  10. <input type=hidden name='task' value='add'>
  11. <table>
  12. .....
  13.  
  14.  
  15.  
  16. <%
  17. if request("task")="lines" then
  18.      linesNo = linesNo + 5
  19.      response.write "return_forms.asp"     
  20. end if 
  21.      
  22. counter = 0
  23. Do While counter < linesNo
  24. %>
  25.  
  26. <tr>
  27. <td  width=20%><input type=text size="20" maxlength="30" name='part_no_<%=counter%>' value='<%=request("part_no_")%>'/></td>
  28. </tr>
  29.  
  30. <%
  31. counter = counter + 1
  32. Loop    
  33. %>
  34.  
  35. <tr>
  36. <td width=20%><form action='return_form.asp' method=post><input type=hidden name='task' value='lines'></form>
  37. <input type=submit name='lines' value='Add Lines'></td>
  38. </tr>
  39.  
  40. ......................(some codes)
  41. <tr>
  42. <td></td>&nbsp;<td><input type=submit value="Save & Print"></td>
  43. </tr>
  44.  
  45.  
  46. </table>
  47.  
  48. </form>
  49.  
Thanks
Aug 11 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
If you're using JavaScript to add text fields dynamically, you only need a normal button, not a submit one. In the onclick handler call a function that adds the fields, e.g.
Expand|Select|Wrap|Line Numbers
  1. var textfield = document.createElement("input");
  2. textfield.type = "text";
  3. // set other properties such as name, id, value, etc.
  4. // get element to append to
  5. elem.appendChild(textfield);
Aug 11 '08 #2

Post your reply

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