By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Hide / Display field in form using drop down.

P: 5
Hi there

I am searching for a method of displaying an extra form field, only when a certain option is selected in a drop down box.

[HTML]
<label for="staff_status">Status: </label>
<select id="staff_status" tabindex="7">
<option value="active" selected="selected">Active</option>
<option value="pending">Pending</option>
<option value="terminated">Terminated</option>
</select>
[/HTML]

All I want is when the option "terminated" is selected, another input field needs to be appear below the drop-down box. Like so:

[HTML]
<label for="staff_enddate">End Date: </label>
<input type="text" id="staff_enddate" value="dd/mm/yyyy" />
[/HTML]

And that is it. Would appreciate any help.

Regards
Joe
Mar 5 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Call a function onchange which has the following code:
Expand|Select|Wrap|Line Numbers
  1. // assuming val is the value of the selected option:
  2. if (val == "terminated") {
  3.     document.getElementById("staff_enddate").style.display = "block";
  4. }
Mar 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.