For a registration form I’m looking for a way to give the user more options based on a number (#) they choose in an formfield.
I’ve searched and found a way to do this with javascript but it does not allow the tag, it does however accept etc. but not a dropdown menu field.
<fieldset>
<legend>Step 2/3: Virtual Machine Options</legend>
<div>
<label for="vmammount">Order # VM's</label>
<select name="vmammount" required="required">
<option value=""></option>
<option value="1">1</option>
<option value="2">3</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div>
<label for="vmos">VM OS 1</label>
<select name="vmos" required="required">
<option value=""></option>
<option value="1">Windows Server 2008</option>
<option value="2">Windows XP</option>
<option value="3">Debian</option>
<option value="4">CentOS</option>
</select>
</div>
<div>
<label for="vmos">VM OS 2</label>
<select name="vmos" required="required">
<option value=""></option>
<option value="1">Windows Server 2008</option>
<option value="2">Windows XP</option>
<option value="3">Debian</option>
<option value="4">CentOS</option>
</select>
</div>
</fieldset>
The OS 1 field is always visible, the other selection field that will follow are dependent on the first field in which the user chooses a value from 1 till 10. Any suggestions?
The best way is to create all os selection elements in HTML / PHP … but only display them if nessesary. Here an example with jQuery, its also possible with plain javascript but needs at least 10times mutch lines of code.
http://jsfiddle.net/vuPwM/2/