This function attempts to hide the options inside of the optgroup tag of the second select box based on the user selected option of the first select box. It works fine in Mozilla but IE7 still shows all the optgroups in the second select box. The idea is to show the appropriate list of states based on what country a user selects without reloading the page.
You can see a sample of the form here:
http://www.allacparts. com/testjs.php
The optgroup tags have an id of ctyCAN and ctyUSA.
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript">
- <!--
- function showhideship() {
- if (document.getElementById('country').value == "") {
- document.getElementById('statewrap').style.display = "none";
- document.getElementById('zipcodewrap').style.display = "none";
- document.getElementById('stateotherwrap').style.display = "none";
- document.getElementById('countryotherwrap').style.display = "none";
- }
- else if (document.getElementById('country').value == "223") {
- document.getElementById('statewrap').style.display = "block";
- document.getElementById('ctyCAN').style.display = "none";
- document.getElementById('ctyUSA').style.display = "block";
- document.getElementById('zipcodewrap').style.display = "block";
- document.getElementById('stateotherwrap').style.display = "none";
- document.getElementById('countryotherwrap').style.display = "none";
- }
- else if (document.getElementById('country').value == "38") {
- document.getElementById('statewrap').style.display = "block";
- document.getElementById('ctyCAN').style.display = "block";
- document.getElementById('ctyUSA').style.display = "none";
- document.getElementById('zipcodewrap').style.display = "block";
- document.getElementById('stateotherwrap').style.display = "none";
- document.getElementById('countryotherwrap').style.display = "none";
- }
- else if (document.getElementById('country').value == "other") {
- document.getElementById('statewrap').style.display = "none";
- document.getElementById('zipcodewrap').style.display = "block";
- document.getElementById('stateotherwrap').style.display = "block";
- document.getElementById('countryotherwrap').style.display = "block";
- }
- else {
- document.getElementById('statewrap').style.display = "block";
- document.getElementById('zipcodewrap').style.display = "block";
- document.getElementById('stateotherwrap').style.display = "block";
- document.getElementById('countryotherwrap').style.display = "block";
- }
- }
- //-->
- </script>
Thanks