Dynamic Forms and DropDown Lists
in Using jQuery
•
11 years ago
I am trying to figure out how to dynamically show/hide certain form elements based on the selection from the drop down list.
My form is defined like so:
<form id="taskentry">
<ul>
<li><label for="tasktype">Task Type</label><select id="tasktype" onClick="getCheckedRadio()">
<option value="house">Around the House</option>
<option value="honey">Honey Do</option>
<option value="bill">Bills</option>
<option value="errand">Errands</option>
<option value="shopping">Shopping</option>
</select>
</li>
<li>
<input type="text" class="required" name="task[name]" id="taskname" placeholder="Task Name" value=""/></li>
<li ><input type="text" name="task[address]" value="" id="taskaddress" placeholder="Address (*)"/></li>
<li ><input type="text" name="task[address]" value="" id="taskaccount" placeholder="Account (*)"/></li>
<li ><input type="text" name="task[address]" value="" id="taskcontact" placeholder="Contact (*)"/></li>
<li ><input type="text" name="task[address]" value="" id="taskamount" placeholder="Amount (*)"/></li>
<li>
<textarea name="task[description]" id="taskdesc" placeholder="Description" rows="5"></textarea>
</li>
<li><input type="text" class="required date" name="task[due]" id="taskdue" placeholder="Task Due" value="" /></li>
<li class="naked"><input type="submit" name="Save" /></li>
</ul>
</form>
So when the option bill is selected I would like to hide the input fields with the ids of taskcontact and taskaddress, and if the errands option is selected I would like to hide the taskamount and taskaccount fields.
Can someone give me some help getting this done?
Thanks
1