Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding form controls on button click... 2

Status
Not open for further replies.

mmaz

Programmer
Nov 22, 2000
347
Hi,

I'm displaying information from a db on a form, and I want to be able to add new records to the db. Now, my form looks like this:

Server ID Server Name Client Name

1 Server1 Client1
2 Server2 Client2


When the user selects the "Add" button, I want to add 3 textbox to the form (for Server ID, Server Name and Client Name). I can do that but the problem is, if the user selects the "Add" button again without saving, there will still be 3 empty textboxes (1 record) and not 6 (for 2 records). So no matter how many times the user selects the "Add" button, the form output will always be:

Server ID Server Name Client Name
1 Server1 Client1
2 Server2 Client2
(empty) (empty) (empty)

How can I print multiple form controls on consecutive "Add" button click without first saving?

Thank you in advance,

Marie :)
 
I think the better for you is to stock a variable in an hidden form like :
<input type=&quot;hidden&quot; name=&quot;form_number&quot; value=&quot;0&quot;>
and after, you just have t make a function to increment the value of this hidden when you click on the &quot;Add&quot; button and after, you just have to loop from 0 to the hidden value to know how many forms you're gonna display !!

Let me know if it solve your probleme
 
you want it to look like this :
--
Server ID Server Name Client Name
1 Server1 Client1
2 Server2 Client2
(empty) (empty) (empty)
(empty) (empty) (empty)
...
--
right ?

i guess that if you only add ONE (empty) row it is because you use something like yourform.yourtextboxi.style.visible=show where i is 1 to 3
so whenever the user clicks the add button, your page will show these 3 named text boxes, as it can't &quot;invent&quot; other ones
therefore, you have to find a way to &quot;create&quot; new text boxes
- either by precreating them as you did for the 3 first ones (just do the same but for 4 or 5 lines, it's NOT elegant but it's efficient)
- or by simply adding new ones (formname.elements[lastindex+1]=new element should work)
don't forget to detect which ones are enabled (if there are) before enabling new ones


 
Aaaah! I see the light at the end of the tunnel.

Thanks, SeAl!

Marie :)
 
Don't forget to make a function to reinitialize the hidden value to 0 when user will click on the &quot;Save&quot; button ;-)
 
Will do, SeAl!

Thank you for your help, SeAl and iza. It's very much appreciated. :)
 
iza, SeAL,

Can you PLEASE have a look at this problem ( something similar to the one above and give me some suggestions )

This might take a while to explain. I have an ASP program (say MyASP.asp) which when accessed displays a form where a user can order from a drop down list of products. The drop down list is populated from a database query made by the ASP program.

Fairly simple so far.

I also use the contents of the database to create a JS client side script which automatically populates a part description field once the part number has been selected.

Still OK.

Now, I have two submit buttons. When the user clicks &quot;Add another product&quot; the form contents are validated and sent to the server side myASP.asp program where the database is accessed again to create a second row of input fields and the HTML page created shows two input rows. The first input row contains the data inputted before the submit and the second row is blank. As you can guess, this is not very efficient.

Now what I would like to be able to do is create a client side JS script that will enable me to create the second row of inputs without having to go back to the server. I can store all the part numbers for the drop down list in a JS array after the first call to the myASP.asp program. But how do I generate the second row of inputs automatically??

I hope that this is clear!! Mise Le Meas,

Mighty :)
 
mmaz,

Did you get this problem sorted and if so what did you do. I would like to be able to generate rows of input on the click of a button. however, as I have no idea how many row I will need, I would rather not create hidden fields first and then make them visible.

I am keen to know how you did it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top