I want a form to be reloaded and preselected with the selection made. Here's the HTML form I have:
<form name='vehicleform'>
<select name='vehiclelist'>
<option value=''>Select</option>
<option value='bus'>Bus</option>
<option value='bike'>Bike</option>
<option value='car'>Car</option>
</select>
<input type='text' name='current'></input>
</form>
When the user opens the page for the first time the dropdown box will be on the Select option by default and the textbox (current) will be empty.
When the user selects any option from dropdown the page needs to reload and that dropdown item should be selected and the value of that dropdown should be in the text input field.
What's the JavaScript function that I need to make this happen?
Like this:
<select name='soemname' id="myid" onchange="document.location.href = 'page.php?var=' + this.value">
<option value=''>Select</option>
<option value='bus'>Bus</option>
<option value='bike'>Bike</option>
<option value='car'>Car</option>
</select>
<script type="text/javascript">
document.getElementById('myid').value = "<?php echo $_GET['var'];?>";
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With