Forum Moderators: open

Message Too Old, No Replies

how to use javascript to create more text box?

create more text box..

         

alucarrd

6:04 am on Sep 25, 2005 (gmt 0)



I need help on how to make my form work.

Basically, my form contains 10 rows of text boxes.

And I want to have a button below the 10 rows of text boxes so when any user clicks on the button, it will create 10 more rows of text boxes (typical client-side javascript). And so on until the button has been clicked for 5 times.

Can anyone give me some hint on how I can start?

Thank you..

Bernard Marx

10:22 am on Sep 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have a look over here for a tip:

[webmasterworld.com...]

Your username is (very nearly) "dracula" backwards.

trialofmiles

7:17 pm on Sep 25, 2005 (gmt 0)

10+ Year Member



What you're asking for is additional table rows and additional text boxes within those rows. Bernard Marx's post from the other thread can help you get started with the table row part, but you'd still need help with the text box part.

Since adding rows to a table can be done several ways, I'll just recommend the DOM methods I'd use (which differs from Bernard Marx's approach).

insertRow (called from a table object) and insertCell (called from the row object returned from insertRow)

document.createElement('input') which returns a new text box, and then needs to have attributes set using setAttribute.

Then the new text box needs to be added to the new cell by using appendChild.

The whole thing would go into a loop to create all 10. You may need to have some iteration logic if the names of the text boxes need to be different.

You can google around for those DOM methods to get a better idea of how to use them.