In Form, Display More Textfield Input If The First One Is Filled

Hello,

I would like to be able to give the possibility to a user to enter several data for one field. To do that, I would like simply display one more textfield input every time this above is filled.

Example : A user can enter all the color he would like to have for his car. In form there is the line "color" with the input textfield attached. If he fills the input textfield, a second one appears just below. If the second one is filled a third one appears below etc…

Do you have an idea of how I could reach that ?

thanks

What you want is a client side script i.e. javascript or jquery. I would recommend adding a button to raise an event which creates the textfield below your initial textfield…a simple search on google would get you enough options of doing this…

check this link http://stackoverflow.com/questions/2145012/adding-rows-dynamically-with-jquery

You’ll need to use jQuery to create new elements on the fly and receive them in PHP as an array. For instance, if you had the following input:




<input type="text" name="color[]" value="" />



you could duplicate that as many times as needed. PHP will receive an array when the form is submitted.

Thanks for all of your response, well for moment I adopted another strategy. I ask the user to write his colors with a comma separating all of them then I collect the string, delete all spaces, and ‘explode’ it. It makes the work, I will lean on something more “fancy” later =P