i'm trying to show/hid various divs based on a user input from a select drop down box. actually, to begin with, i'm trying to directly implement the code shown in jQuery dropdown hide show div based on value, however i'm missing something simple which prevents it from working at http://www.intertwineimages.com/form2.html here is my complete code, can anyone point me in the right direction?
<html>
<script type="text/javascript">
hideAllDivs = function () {
$("#hourly").hide();
$("#per_diem").hide();
$("#fixed").hide();
};
handleNewSelection = function () {
hideAllDivs();
switch ($(this).val()) {
case '1':
$("#hourly").show();
break;
case '2':
$("#per_diem").show();
break;
case '3':
$("#fixed").show();
break;
}
};
$(document).ready(function() {
$("#project_billing_code_id").change(handleNewSelection);
// Run the event handler once now to ensure everything is as it should be
handleNewSelection.apply($("#project_billing_code_id"));
});
</script>
<select id="project_billing_code_id">
<option value="">Pick one</option>
<option value="1">1-Hourly</option>
<option value="2">2-Per Diem</option>
<option value="3">3-Fixed</option>
</select>
<div id="hourly">Hourly</div>
<div id="per_diem">Per Diem</div>
<div id="fixed">Fixed</div>
</html>
EDIT: corrected code
<html>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
hideAllDivs = function () {
$("#hourly").hide();
$("#per_diem").hide();
$("#fixed").hide();
};
handleNewSelection = function () {
hideAllDivs();
switch ($(this).val()) {
case '1':
$("#hourly").show();
break;
case '2':
$("#per_diem").show();
break;
case '3':
$("#fixed").show();
break;
}
};
$(document).ready(function() {
$("#project_billing_code_id").change(handleNewSelection);
// Run the event handler once now to ensure everything is as it should be
handleNewSelection.apply($("#project_billing_code_id"));
});
</script>
<select id="project_billing_code_id">
<option value="">Pick one</option>
<option value="1">1-Hourly</option>
<option value="2">2-Per Diem</option>
<option value="3">3-Fixed</option>
</select>
<div id="hourly">Hourly</div>
<div id="per_diem">Per Diem</div>
<div id="fixed">Fixed</div>
</html>