| Refresh | Home EGTry.com

show or hide an element from display and layout


<html>
<head>
<script>

var allid=['div1', 'div2'];

function selectit(id) {
  //alert("select block of id="+id);
 for(var i=0; i<allid.length; i++) {
   var div=document.getElementById(allid[i]);
   //alert("div="+div);
   if (allid[i] == id) {
     div.style.display='';
   } else {
     div.style.display='none';
   }
 }
 return false;
}

</script>
<body>

  <form>

    Start:<br/>
    <div id="div1">
      Select Country: <br/>
    <select id="s1" name="country" multiple size=5>
      <option value="China">China, PRC</option>
      <option value="USA">United States of American</option>
    </select>
    </div>

    <div id="div2" style="display:none" >
      Select States:
      <select name="state" multiple size=5>
        <option value="TX">Texas</option>
        <option value="CA">California</option>
      </select>
    </div>
    end:<br/>

    <a href="#" onclick="return selectit('div1')">Select Country</a>
    <a href="#" onclick="return selectit('div2')">Select State</a>
  </form>
</body>
</html>