473,506 Members | 16,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add extra input box in the same form when the button is clicked??

44 New Member
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.  
  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'>
  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 10 '08 #1
6 1630
DrBunchman
979 Recognized Expert Contributor
Hi yimma216,

What actually happens when you run this? Does it error?

I think the problem is probably that you have two form opening tags and only one form closing tag. Make sure that both of your forms are closed correctly if you did intend to have two of them on your page.

Also you have two hidden variables called 'task' both with different values which I think is probably passing the wrong value to Request("task"). You can debug this by checking the value with a Response.Write Request("task") just before you test whether it's value is equal to "lines".

Take a look at these points and let me know how you get on.

Dr B
Aug 11 '08 #2
yimma216
44 New Member
yes, there is a problem in the code. I found out i could not use nested form in html. Is moving on now.
Aug 11 '08 #3
yimma216
44 New Member
hi Dr,

I have fixed the problem you mentioned and got some other advices.
However, when I tried to run the code, the application timed out.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim linesNo 
  3. Dim counter
  4.  
  5. 'default value for the input
  6. linesNo = 5
  7.  
  8. Set conn = Server.CreateObject("ADODB.Connection")
  9. Set cmd = Server.CreateObject("ADODB.Command")
  10. Set cmd2 = Server.CreateObject("ADODB.Command")
  11. ..................etc 
  12.  
  13. 'form submit button was clicked
  14. If request("save")<>"" Then
  15. conn.Open  "Driver={SQL Native Client};Server=cslproxy;database=gra;Trusted_Connection=yes;"
  16.  
  17. counter = 0
  18.  
  19.       Set cmd.ActiveConnection = conn
  20.       cmd.CommandText = "add_goods"
  21.       cmd.CommandType = 4
  22.       cmd.Parameters.Refresh
  23.       ...............etc
  24.       set rs = cmd.execute
  25.  
  26. Do While counter < request("lines") 
  27.     If request("part_no_"&counter) <> "" then
  28.       Set cmd2.ActiveConnection = conn
  29.       cmd2.CommandText = "add_parts"
  30.       cmd2.CommandType = 4
  31.       cmd2.Parameters.Refresh
  32.       cmd2.Parameters("@gra_id") =  rs(0)
  33.     .......................etc
  34.        cmd2.execute
  35.     End If 
  36.     counter = counter + 1
  37. Loop
  38.  
  39.  
  40. response.redirect "print_out.asp?gra_id=" & rs(0)
  41. rs.close
  42. conn.close
  43. else
  44.  
  45. ' form submit wasn't clicked...
  46.         ' we had a hidden lines value
  47.         if request("lines")<>"" then
  48.             ' populate linesNo with that value
  49.             linesNo = request("lines")
  50.             ' Add Lines submit button was clicked
  51.             if request("addLines")<>"" then
  52.                 ' so add five to current lines value
  53.                 linesNo = linesNo + 5
  54.                 'response.write vbcrlf & linesNo
  55.             end if
  56.         end if
  57.  
  58.  
  59.  
  60. %>
  61. <html>
  62. <head></head>
  63. <body>
  64. ...............................etc
  65.  
  66. <form action='return_form.asp' method=post>
  67. <input type=hidden name='lines' value='<%=linesNo%>'>
  68. ........etc
  69.  
  70.  
  71. <table>
  72.   <tr>
  73.     <td width=20%>Part No</td><td  width=40% colspan=2>Description</td></td><td width=20%>Quantity</td>
  74.   </tr>
  75.  
  76. <%    
  77. counter = 0
  78. Do While counter < linesNo
  79. %>
  80.  
  81.   <tr>
  82.       <td  width=20%><input type=text size="20" maxlength="30" name='part_no_<%=counter%>' value='<%=request("part_no_"&counter)%>'/></td><td  width=40% colspan=2><input type=text size='70' maxlength='100' name='desc_<%=counter%>' value='<%=request("desc_"&counter)%>' /></td><td><input type=text size="5" maxlength="10" name='quantity_<%=counter%>' value='<%=request("quantity_"&counter)%>' /></td>        
  83.   </tr>
  84.  
  85.  <%
  86.  counter = counter + 1
  87.   Loop
  88.  %>
  89.  
  90. <tr>
  91.   <td width=20%><input type=submit name='addLines' value='Add Lines'></td>
  92. </tr>
  93. </table>
  94. ........................etc
  95.  
  96.  
  97.   <tr>
  98.      <td></td>&nbsp;<td><input type=submit name="save" value="Save & Print"></td>
  99.   </tr>
  100.  
  101. </table>
  102.  
  103. </form>
  104.  
  105. <%
  106. conn.close
  107. End if
  108.  
  109. %>
  110. </body>
  111. </html>
  112.  
Aug 12 '08 #4
yimma216
44 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Do While counter < request("lines") 
  4.     If request("part_no_"&counter) <> "" then
  5.       Set cmd2.ActiveConnection = conn
  6.       cmd2.CommandText = "add_parts"
  7.       cmd2.CommandType = 4
  8.       cmd2.Parameters.Refresh
  9.       cmd2.Parameters("@gra_id") =  rs(0)
  10.     .......................etc
  11.        cmd2.execute
  12.     End If 
  13.     counter = counter + 1
  14. Loop
  15.  
  16.  
I am suspecting the counter < request("lines").
But do not know how to refine the code
Aug 12 '08 #5
jhardman
3,406 Recognized Expert Specialist
When I get scripts timing out, I go back and check through my loops. change them one at a time to one shot statements (in other words, make them not loop) and that will usually tell me which loop is at fault. That said, as long as the loop advances (and you have a counter = counter + 1 line) the only time I have this problem is if I have an error on my page and a "on error ..." error handler which keeps the page moving despite the error. Try commenting out your error handler to see what is really going on.

Jared
Aug 12 '08 #6
yimma216
44 New Member
When I get scripts timing out, I go back and check through my loops. change them one at a time to one shot statements (in other words, make them not loop) and that will usually tell me which loop is at fault. That said, as long as the loop advances (and you have a counter = counter + 1 line) the only time I have this problem is if I have an error on my page and a "on error ..." error handler which keeps the page moving despite the error. Try commenting out your error handler to see what is really going on.

Jared

Thank you Jared.
The mistakes were the request("lines") - (someone told me). I tried casting that to integer and the system seems to be happy now.
Aug 12 '08 #7

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

Similar topics

1
18755
by: Jawahar Rajan | last post by:
All, I am using a few Input type of "Image" instead of a classic submit button in a form to achieve various tasks for example image1 - add user image2 - modify user image3 - delete user...
3
5160
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
2
6932
by: J.R | last post by:
Greetings, I'm adding dynamically created input type='file' controls via JavaScript. However when I try to access they do not seem to be returned in the form collection. Any ideas? Thanks,...
2
10975
by: Andrew Parish | last post by:
I have a page with an input text box and a button which validates the text (see below). If I click inside the text box, the button is highlighted. If I enter some text inside the box and press...
2
16290
by: Cantekin Guneser | last post by:
in my program when a button clicked , a process starts, but i need to take two value, becouse of this, i use a new windows form, to make my program more userfriendly, i was thinking is it possible...
3
21241
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image'...
1
3436
by: namanhvu | last post by:
Hi everyone, I'm trying to create a form where the radio button is automatically selected when the input text field beside it is clicked. I know I need to use "onClick" somewhere but I don't...
9
24734
by: Prakash Singh Bhakuni | last post by:
am replacing the default "Browse..." button for input type=file. This works fine except that the form will only submit after the SUBMIT button is clicked twice. Any ideas on why this is happening...
3
3436
by: yimma216 | last post by:
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 would be a form in a form using vbscipt...
0
7220
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,...
0
7105
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
7308
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
7371
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...
0
5617
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,...
0
3188
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
0
410
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...

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.