Page 1 of 1

Add new text box based of value entered

Posted: Tue Oct 05, 2010 10:27 am
by faizpayi
Hi,

Is it possible to add text box based on another value entered in a text box.For example,if a person adds the number of children in a box as 3 ,three new text box should come asking for the name of the children.I tried using if condition in php but when I use <input type="text" name="name1" id="name1" /> inside php tag,error is thrown.

Thanks for the help in advance


Faiz

Re: Add new text box based of value entered

Posted: Tue Oct 05, 2010 11:50 am
by social_experiment
Something like :

Code: Select all

<?php
 $value = $_POST['value'];
 if ($value > 0) {
  for ($i = 1; $i <= $value; $i++) {
   echo '<input type="text" name="field_'. $i .'" />';
   echo '<br />';
  }
} ?>

Re: Add new text box based of value entered

Posted: Thu Oct 07, 2010 2:07 am
by faizpayi
Hi...thanks for the codes...this will work on submit or posting the values right...it there anyway that when i choose a value from a list box,suppose 2,then immediately two text box should appear??

Re: Add new text box based of value entered

Posted: Thu Oct 07, 2010 3:11 am
by social_experiment
faizpayi wrote:it there anyway that when i choose a value from a list box,suppose 2,then immediately two text box should appear??
You can modify the script to work with a dropdown menu option but this will still have to be submitted if you are going to use php. For an 'immediate' option, you should look into javascript.