how to select checkbox from value in cookie ?

F

find clausen

qqq = GetCookie("whatever");

How do I select a chekbox in a form if qqq = yes

TIA
 
L

Laurent Bugnion

Hi,

find said:
qqq = GetCookie("whatever");

How do I select a chekbox in a form if qqq = yes

TIA

var qqq = GetCookie("whatever");
var nCheckbox = document.getElementById( "myCheckbox" );
if ( nCheckbox )
{
nCheckbox.checked = ( qqq == "yes" );
}

HTH,
Laurent
 
A

ASM

find clausen a écrit :
qqq = GetCookie("whatever");

How do I select a chekbox in a form if qqq = yes

and how do you set cookie ?
before to try to read it ...
 
F

find clausen

Hi,



var qqq = GetCookie("whatever");
var nCheckbox = document.getElementById( "myCheckbox" );
if ( nCheckbox )
{
nCheckbox.checked = ( qqq == "yes" );
}

thanx but I don't understand how it works, the checkbox:

<input type="Checkbox" name="whatever" value="yes" title="whatever">

should there be an ID in the input line ?
 
A

ASM

find clausen a écrit :
SetCookie("whatever", form.whatever.value);

and this time : what is 'form' ?

if(GetCookie("whatever") && form.whatever) {
if(GetCookie("whatever") != '')
form.whatever.value = GetCookie("whatever");
else alert('no value was saved for \'whatever\' !');
form.whatever.focus();
form.whatever.select();
}

if form is something like :
form = document.forms['myForm'];
and if GetCookie(() returns true/false or a value
 
F

find clausen

find clausen a écrit :
SetCookie("whatever", form.whatever.value);

and this time : what is 'form' ?

if(GetCookie("whatever") && form.whatever) {
if(GetCookie("whatever") != '')
form.whatever.value = GetCookie("whatever");
else alert('no value was saved for \'whatever\' !');
form.whatever.focus();
form.whatever.select();
}

if form is something like :
form = document.forms['myForm'];
and if GetCookie(() returns true/false or a value

It's a function that fires onsubmit:
function SendForm(form)

and this body onload:
function OldForm(form)

you can check it out here:

www.photopress.dk/romo_booking/

zform.js is the script for that.
There are two check boxes that I would like thie feature on.
 
F

find clausen

find clausen a écrit :
SetCookie("whatever", form.whatever.value);

and this time : what is 'form' ?

if(GetCookie("whatever") && form.whatever) {
if(GetCookie("whatever") != '')
form.whatever.value = GetCookie("whatever");
else alert('no value was saved for \'whatever\' !');
form.whatever.focus();
form.whatever.select();
}

if form is something like :
form = document.forms['myForm'];
and if GetCookie(() returns true/false or a value

I have tried this:
if (GetCookie("adsl") == 'yes') form.adsl.checked = true;
if (GetCookie("wifi") == 'yes') form.wifi.checked = true;
But then the cboxes are select allways ... (???)
 
L

Laurent Bugnion

Hi,

find said:
thanx but I don't understand how it works, the checkbox:

<input type="Checkbox" name="whatever" value="yes" title="whatever">

should there be an ID in the input line ?

Well, yes. If you want to use getElementById, you need an ID... ;-)

var qqq = GetCookie("whatever");
var nCheckbox = document.getElementById( "whatever" );
if ( nCheckbox )
{
nCheckbox.checked = ( qqq == "yes" );
}

with

<input type="checkbox" id="whatever" name="whatever"
value="yes" title="whatever">

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,880
Members
47,417
Latest member
DarrenGaun

Latest Threads

Top