problem with select boxes - second options based on first selection
- by Charles Marsh
Hello All,
I just posted a question about opening in a new window but if I use window.location it doesn't work?? is there a problem with my javascript?
<script type="text/javascript">
function setOptions(chosen){
var selbox = document.formName.table;
selbox.options.length = 0;
if (chosen == " ") {
selbox.options[selbox.options.length] = new Option('No diploma selected',' ');
}
if (chosen == "1") {
selbox.options[selbox.options.length] = new Option('first choice - option one','http://www.pitman-training.com');
selbox.options[selbox.options.length] = new Option('first choice - option two','onetwo');
}
if (chosen == "2") {
selbox.options[selbox.options.length] = new Option('second choice - option one','twoone');
selbox.options[selbox.options.length] = new Option('second choice - option two','twotwo');
selbox.options[selbox.options.length] = new Option('second choice - option three','twothree');
selbox.options[selbox.options.length] = new Option('second choice - option four','twofour');
}
if (chosen == "3") {
selbox.options[selbox.options.length] = new Option('third choice - option one','threeone');
selbox.options[selbox.options.length] = new Option('third choice - option two','threetwo');
}
}
</script>
Its a little messy I know...
<form name="formName" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="optone" size="1" onchange="setOptions(document.formName.optone.options[document.formName.optone.selectedIndex].value);">
<option value=" " selected="selected">Please select a diploma</option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
<select name="table" size="1" >
<option value=" " selected="selected">No diploma selected</option>
</select>
<input type="submit" onclick="ob=this.form.table;window.location(ob.options[ob.selectedIndex].value)"/>
</form>
to be honest I'm not happy with this anyway I want a way to hide the Submit button until the second selected box has been selected...but I'm no java expert! Can anyone point me in the right direction?