I am a complete beginner to JavaScript and learning as I go along.
I have a dropdown list of "channel" and would like to show a different set of fields depending on user selection:
<selectonchange="channelChoice(this)"name="Channel"id="Channel"><optionvalue="Banner_">Banner</option><optionvalue="Retailer_">Retailer</option><optionvalue="Print_">Print</option><optionvalue="Social_">Social</option><optionvalue="Website_">Website</option></select><divid="retailerOption"style="display:none"><selectonchange="retailerChoice(this)"name="Retailer"id="Retailer"><optionvalue="Amazon">Amazon</option><optionvalue="Other">Other</option></select><inputtype="text"id="RetailerName"placeholder="select your retailer"style="display:none;"></div><divid="printOption"style="display:none"><selectonchange="printChoice(this)"name="Print"id="Print"><optionvalue="Magazine">Magazine</option><optionvalue="Journal">Journal</option><optionvalue="Stands">Stands</option><optionvalue="Other">Other</option></select><inputtype="text"id="PrintType"name="PrintType"placeholder="what is your print asset type?"style="display:none;"></div><divid="socialOption"style="display:none"><selectname="SocialMedia"id="SocialMedia"><optionvalue="Facebook">Facebook</option><optionvalue="Instagram">Instagram</option><optionvalue="YouTube">YouTube</option></select><selectname="SocialPostFormat"id="SocialPostFormat"><optionvalue="Carousel">Carousel</option><optionvalue="Static_Post">Static Post</option><optionvalue="Story">Story</option><optionvalue="Video">Video</option></select></div><divid="webOption"style="display:none"><selectonchange="webChoice(this)"name="Country"id="Country"><optionvalue="AwardLogo">Award Logo</option><optionvalue="RetailerLogo">Retailer Logo</option><optionvalue="LandingPageImage">Landing Page Image</option></select></div>
Can someone please help me how I can code so when a user selects "Retailer" then Retailer Option DIV will show but then if they selects "Print", Retailer Div disappears but "Print" DIV appears etc?
Showing / hiding a different set of fields depending on selection from a dropdown
in JavaScript
Posted
Hello,
I am a complete beginner to JavaScript and learning as I go along.
I have a dropdown list of "channel" and would like to show a different set of fields depending on user selection:
I had been playing around with this JavaScript:
I could display fields no problem but my issue is to hide if, for example, a user select "Print" after initially selecting "Retailer".
Played around by adding "none" line:
if(elem.value == "Retailer_") document.getElementById('retailerOption').style.display = 'block'; else if(elem.value !== "Retailer_") document.getElementById('printOption').style.display = 'none'; else if(elem.value == "Social_") document.getElementById('socialOption').style.display = 'block';
and so on, but didn't work.
Can someone please help me how I can code so when a user selects "Retailer" then Retailer Option DIV will show but then if they selects "Print", Retailer Div disappears but "Print" DIV appears etc?
Thank you.