I have a contact form that has a drop-down for referral source. If Magazine is selected from referral source, I want to show another, hidden drop-down menu for which magazine, If another option is then selected for referral source, I want the magazine list to disappear. So far I have the following (weak sauce) JavaScript:
function showObject(id) {
document.getElementById(id).style.display = 'block';
}
function hideObject(id) {
document.getElementById(id).style.display = 'none';
}
And the following HTML (part of a form):
<label>Referral Source </label>
<select class="contact-input-dropdown">
<option value="">Select One (Required)</option>
<option value="Email from Us">Email from Us</option>
<option value="Friend or Associate">Friend or Associate</option>
<option value="Flyer/Mailing">Flyer/Mailing</option>
<option value="Magazine">Magazine</option>
<option value="Online Search Engine">Online Search Engine</option>
<option value="Tradeshow">Tradeshow</option>
<option value="Social Media">Social Media</option>
</select>
<br>
<label id="magazine-label" style="display:none">Magazine</label>
<select id="magazine" class="contact-input-dropdown" style="display:none;" name="magazine">
<option value="Not Specified">Select One</option>
<option value="X Management">X Management</option>
<option value="Test Mag 1">Test Mag 1</option>
<option value="Test Mag 2">Test Mag 2</option>
<option value="Test Mag 3">Test Mag 3</option>
</select>
I want to check the Referral Source whenever it’s changed, show the Magazine input if Magazine was chosen, or hide it if Magazine was not chosen.
Using your javascript functions you can do the following (you can break it out into its own function if you want):
In your code: