Click to See Complete Forum and Search --> : set cookie on radio buttons


Toink
11-27-2003, 02:59 AM
Hi! Can somebody help me how to set and get a cookie for the selected value of a radio button?

Say radio1 has value of 1, radio2 has value of 2, and radio3 has value of 3. I need to save which value was selected and later retrieve it.

Any help will be much appreciated. Thanks!

Khalid Ali
11-27-2003, 06:23 AM
you only need to know how to save and read back a cookie,where the value comes from doesn't matter when its in javascript.

Below is the link for a simple cookie useage script

Link for cookie useage (http://www.webapplikations.com/pages/html_js/document/SimpleLoginCookieScript.html)


and to get value froma radio button, use something like this

value = document.formName.radioGroupName[arraayIndex].value

Toink
11-27-2003, 07:04 PM
Thanks Khalid!

Could you just maybe check the function below if it's correct for what I intend to do?

I have a radio button group named "Q1" with 3 radio buttons (button 1 value is "3", button 2 is "2", button 3 is "1"). Once the user selects one of the buttons, I need to save his selection meaning the value of the button whether it's 1,2, or 3.

====================
.
.
.
function set_question(form) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
var q1 = form.Q1.value
SetCookie ("Q1", q1, expdate);
}
.
.
.
====================

Thanks so much!