i want to set a cookie for dropdown menu in the html form ,when refresh the page i should get the value that is stored in the cookie in my drop down box.
I have written code for input box as follows:
<script type="text/javascript">
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
</script>
<input name="order_num" type="text" size="10" value="<?php if(isset($_COOKIE["order_num"])) echo $_COOKIE["order_num"];?>" onblur="setCookie(this.name,this.value,60*60*2)" />
In the similar way i want to write the cookie for dropdown box.the code for drop down menu is
follows:
<select name="quality" onChange="setCookie('quality',this.value,60*60*2)" selected="" >
<option >Select One</option>
<option value="good" selected="good">Good</option>
<option value="ok" selected="ok">A bit low but we can use it</option>
...
</select>
<input type="checkbox" name="proceed_opt[]" value="I will upload new Image" onblur="setCookie(this.name,this.value,60*60*2);>
Insert Option "I will upload new Image"</td></tr>
<input type="checkbox" name="proceed_opt[]" value="I approve this sample for a Night Light" onblur="setCookie(this.name,this.value,60*60*2);>
Insert Option "<font face="Arial, Helvetica, sans-serif" size="2">I approve this sample for a Night Light</font>"
any one help me to set the cookie….
You should check if the cookie value equals the select item. If so, give the item the HTML
selectedattribute.This code may need some modification because I didn’t test it. But the main idea is there.
Edit: Example for checkboxes:
The problem with this code is that it won’t work if the user doesn’t click the check box, but choose it using the keyboard for example.