This is similar to another problem I was having with text inputs and posted about here
http://www.dreamincode.net/forums/showtopic64855.htmI have an 'edit your post' page where the dropdown menus are selected initially from php variables defined in a MYSQL database. I also have an 'edit' button that enables the user to change what they want to select for each category. I'm now trying to add a 'reset' button that returns things to the way they were before the edit began. I got it to work with the text inputs with some help of a guy on this forum like this:
CODE
<script type="text/javascript">
function rest_name_enable(){
if(document.all || document.getElementById){
document.form_name.rest_name.disabled = false;
document.form_name.rest_name.defVal = document.form_name.rest_name.value;
}
}
function rest_name_reset(){
if(document.all || document.getElementById){
if(document.form_name.rest_name.disabled == false){
var r = confirm("This will delete whatever you just typed!!\nAre you sure you want to reset the Restaurant Name?");
if(r == true){
document.form_name.rest_name.disabled = true;
document.form_name.rest_name.value = document.form_name.rest_name.defVal;
}
else{
}
}
else{
}
}
}
</script>
<form name="form_name">
<input name="rest_name" type="text" value="<?php echo $row[rest_name]?>" disabled="disabled">
<a href = "java script:rest_name_enable()">edit</a>
<a href = "java script:rest_name_reset()">reset</a><br>
The initial values for the drop down menus are selected like this:
CODE
<select name='price' disabled="disabled">
<option <?php if ($row[price]=='1') {echo "selected";} ?> value='1'>Under $10</option>
<option <?php if ($row[price]=='2') {echo "selected";} ?> value='2'>$10-$20</option>
<option <?php if ($row[price]=='3') {echo "selected";} ?> value='3'>Over $20</option>
</select>
And the same code that works to enable/disable the text inputs work for the dropdown menus as well, however, I can't figure out how to get the values to reset. Basically, just as the text input reset script assigns the value of the text field using
CODE
document.form_name.rest_name.value = document.form_name.rest_name.defVal;
I need to find a way of setting the selection in a drop down menu. Thanks in advance!