My Javascript switch case is not working for some reason, and I can not understand it, I try to display Only a certain option is selected for a certain option,
function showhyschool (obj) {var cursel = obj.options [obj.selectedIndex] .value switch (curel) {case ' 0-2 ': Document.getElementById (' school '). Style.display = "none" break; Case '3-5': document.getElementById ('school'). Style.display = "block" break; Case '6-8': document.getElementById ('schools'). Style.display = "block" break; Case '9-11': document.getElementById ('school'). Style.display = "block" break; Case '12 -14 ': document.getElementById (' school '). Style Disconnect = "block" break; Case '15 -16': document.getElementById ('school'). Style Disconnect = "block" break; Case '17-18': document.getElementById ('schools'). Style.display = "block" break; Case '19 more ': document.getElementById (' schools'). Style.display = "block" break; Default: document.getElementById ('schools'). Style.display = "none"}} Here's HTML:
& lt; P & gt; & Lt; Label = "childrenAge" & gt; Children of the children are still living at home: & lt; / Label & gt; & Lt; Select Name = "Children Next" id = "Children Next" onchange = "ShowHide School (this);" & Gt; & Lt; Options & gt; Choose one & lt; / Options & gt; & Lt; Option value = "0-2" & gt; 0-2 & lt; / Options & gt; & Lt; Option value = "3-5" & gt; 3-5 & lt; / Options & gt; & Lt; Option value = "6-8" & gt; 6-8 & lt; / Options & gt; & Lt; Option value = "9-11" & gt; 9-11 & lt; / Options & gt; & Lt; Option value = "12-14" & gt; 12-14 & lt; / Options & gt; & Lt; Option value = "15-16" & gt; 15-16 & lt; / Options & gt; & Lt; Option value = "17-18" & gt; 17-18 & lt; / Options & gt; & Lt; Option value = "19 and more" & gt; 19 more & lt; / Options & gt; & Lt; / Select & gt; & Lt; / P & gt; & Lt; Div id = "schools" style = "display: none" & gt; & Lt; P & gt; & Lt; Label = "schoolName" & gt; Which schools do they include: & lt; / Label & gt; & Lt; Input type = "text" name = "schoolName" /> & Lt; / P & gt; & Lt; / Div & gt;
You do not need a switch case:
If obj.options [obj.selectedIndex] .value! = "Select one" and obj.options [obj.selectedIndex] .value! = "0-2") {document.getElementById ('school' ) .style.display = "block"; } And {document.getElementById ('schools'). Style.display = "none"; }
Comments
Post a Comment