Forum Moderators: open
Thank you in advance!
<select name="test_select" id="testSelect">
<option value="" selected="selected">Choose an option:</option>
<option value="5">Fiver</option>
<option value="10">Ten spot</option>
<option value="100">Bill</option>
</select>
<script type="text/javascript">
<!--
var theSelect = document.getElementById('testSelect');
theSelect.onchange = function(){
if(this.value && this.value!= ''){
location.href = '/directory/retrieve_data.php?id='+this.value;
}
}
//-->
</script>
<noscript>
<input type="submit" />
</noscript>
:)
<form action="/directory/retrieve_data.php" method="get">
<select name="id" id="testSelect">
<option value="" selected="selected">Choose an option:</option>
<option value="5">Fiver</option>
<option value="10">Ten spot</option>
<option value="100">Bill</option>
</select> <input type="submit" value="Go!" id="submitHide" />
</form>
<script type="text/javascript">
<!--
var theSelect = document.getElementById('testSelect');
var theSubmit = document.getElementById('submitHide');
theSubmit.style.display = 'none';
theSelect.onchange = function(){
if(this.value && this.value!= ''){
location.href = '/directory/retrieve_data.php?id='+this.value;
}
}
//-->
</script>
My final nitpick would be to remove the comment tags in the script:
<script type="text/javascript">
<!--
...
//-->
</script>
Would become:
<script type="text/javascript">
...
</script>
Below is a quote [javascript.crockford.com] from Douglas Crockford [crockford.com]:
Do not use the <!-- //--> hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years. <!-- //--> is supposed to signal an HTML comment. Comments should be ignored, not compiled and executed. Also, HTML comments are not to include --, so a script that decrements has an HTML error.