javascript - Hiding/Showing Drop Down menus depending on another option -
i trying make when person selects option drop down menu, drop down menu shows up. if have drop down menu 3 choices, "vancouver, "singapore","new york". when user selects vancouver drop down menu shows couple of options, if select new york drown down menu shows up. make things complicated using php going running things on server side eventually.
echo "<script type=\"text/javascript\">"; echo "function getdropdown(sel){"; echo "hideall();"; echo "document.getelementbyid(sel.options[sel.selectedindex].value).style.display "; echo "= 'block';"; echo "}"; echo "function hideall(){"; echo "document.getelementbyid(\"vancouver\").style.display = 'none';"; echo "document.getelementbyid(\"singapore\").style.display = 'none';"; echo "document.getelementbyid(\"newyork\").style.display = 'none';"; echo "}"; echo "</script>"; echo "<tr>"; echo "<td align=\"right\">"; echo "<td>"; echo "<select name=\"optiondrop\" onchange=\"getdropdown(this)\">"; echo "<option value=\"\">please select</option>"; echo "<option value=\"vancouver\">vancouver</option>"; echo "<option value=\"singapore\">singapore</option>"; echo "<option value=\"newyork\">new york</option>"; echo "</select>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align=\"right\">city</td>"; echo "<td>"; echo "<div id=\"vancouver\" style=\"display: none;\">"; echo "<select name=\"optiondrop\" >"; echo "<option value=\"\">please select</option>"; echo "</select>"; echo "</div>"; echo "<div id=\"singapore\" style=\"display: none;\">"; //echo "<select name=\"optiondrop2\">"; // echo "<option value=\"\">please select2</option>"; echo "sing"; echo "</div>"; echo "<div id=\"newyork\" style=\"display: none;\">"; echo "new york"; echo "</div>"; echo "</td>"; echo "</td>"; echo "</tr>"; right when select option "vancouver" drop down menu shot up, , when selected other options text shows up. if uncomment lines
//echo "<select name=\"optiondrop2\">"; // echo "<option value=\"\">please select2</option>";
then nothing works anymore. no matter option select nothing shows up. stuck , cant figure out wrong it.
hum... first of i'll give hint might have begged many years ago:
closing php tag within php file won't break code. if want display html doing in code posted, following:
<?php $variable = "test"; // random things blabla. ?> <span class="test"> <?php echo $variable; ?> </span> <?php $something = "something_else"; // other php ?> about problem, there go: http://codepen.io/anon/pen/gxyte
Comments
Post a Comment