How can I have one dropdown hide/show depending on the selec

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) …

via HTML Language Development » Search Results » ajax:

How can I have one dropdown hide/show depending on the selec

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):


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):
onchange=”if(this.options[this.selectedIndex].value == ‘Magazine’) showObject(‘magazine’); else hideObject(‘magazine’); ”In your code:
>Referral Source


……………………………………….

If you are on a PHP server you could use ajax for it which would be the most efficient method.
Pass a value using document.getElementByID to the ajax call and then dynamically change the content of the second element based on the selection of the first.
To save on coding it in here this is a link to a great tutorial for the process.
http://thejoysofcomputing.wordpress.com/2010/02/19/change-a-drop-down-when-other-changes-in-ajax-way/

For more info: How can I have one dropdown hide/show depending on the selec

HTML Language Development » Search Results » ajax

How can I have one dropdown hide/show depending on the selec

Share this post:

Related Posts

Leave a Comment