Home|Sitemap|Contact

How can you change a drop down list contents on some action?

Here, the event is simply a button being pushed. Possibly you would want to change the contents of one drop down list based on the selection in a previous drop down list or the checking of a check box. The concept is the same in any event.

The Code

  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005, 2006 Roderick Divilbiss">

<script language="javascript" type="text/javascript">
<!--
var current=1;

function changeSelect() {
if (current==1) {
    document.getElementById('sDiv').innerHTML=
     '<select name="province" id="province" onChange="calculate()">'+
     '<option value="QC">QUEBEC</option>'+
     '<option value="ON" selected>ONTARIO</option>'+
     '<option value="BC">BRITISH COLUMBIA</option></select>';

    current=0;
}else{
    document.getElementById('sDiv').innerHTML=
     '<select name="stateForCountry" id="stateForCountry">'+
     '<option>Kansas</option>'+
     '<option>Missouri</option></select>';

    current=1;
    }
}
//-->
</script>
</head>

<body>
<div id="sDiv">
  <select name="stateForCountry">
    <option>Kansas</option>
    <option>Missouri</option>
  </select>
</div>
<br><input type="button" value="change" onclick="changeSelect();">

</body>
</html>


Most Popular Pages On rodsdot.com

Client Side Includes Using JavaScript
Creating A JavaScript Slider Input in JavaScript
Creating Conditional Links With ASP
Dynamically Adding Rows and Fields To A Table Based Form
Geo-Coding IP Addresses
How To Make A Pop Over Menu
JavaScript Date Validation DD/MM/YYYY
JavaScript Date Validation MM/DD/YYYY
Parameterized SQL Using Multiple Form Inputs and Filtering
Play A WAV File On Mouseover
Pop Over Form
Resorting A Multi-Dimensional Table Using Client-Side JavaScript
Scripting Remote Images in JavaScript
Using AJAX to Return HTML For Dynamic Forms
Using Images For CAPTCHA
Using Parameterized SQL with ASP and MS Access
Why JavaScript As The HREF Of A Link Is Bad