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
Add new text box based of value entered
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Add new text box based of value entered
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 />';
}
} ?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Add new text box based of value entered
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??
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Add new text box based of value entered
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.faizpayi wrote:it there anyway that when i choose a value from a list box,suppose 2,then immediately two text box should appear??
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering