radio checked or not

B

Bob

Hi at all

I have an <input type="radio" bame="first" value="choice1" taht I want be
checked if a global var is true



How can I do please?
 
E

Evertjan.

Bob wrote on 26 jul 2007 in comp.lang.javascript:
Hi at all

I have an <input type="radio" bame="first" value="choice1" taht I want
be checked if a global var is true


<input type="radio" name="first" id="first" value="choice1">

<script type='text/javascript'>

var myGlobalVariable = true;

if (myGlobalVariable)
document.getElementById("first").checked = true;

</script>
 
A

ASM

En réponse à Bob qui nous a susurré, en date du : 26/07/07 9:36, le
message sibyllin suivant :
I have an <input type="radio" bame="first" value="choice1" taht I want be
checked if a global var is true

How can I do please?

onclick=" if(myGlobal) document.forms[0].first[0].checked=true;"

onclick=" if(myGlobal) var R = document.forms[0].first;
for(var i=0; i<R.length; i++)
if(R.value=='choice1') R.checked=true;"
 
R

RobG

Bob wrote on 26 jul 2007 in comp.lang.javascript:



<input type="radio" name="first" id="first" value="choice1">

<script type='text/javascript'>

var myGlobalVariable = true;

if (myGlobalVariable)
document.getElementById("first").checked = true;

or:

document.getElementById("first").checked = myGlobalVariable;
 
E

Evertjan.

RobG wrote on 26 jul 2007 in comp.lang.javascript:
or:

document.getElementById("first").checked = myGlobalVariable;

No, Rob,

Because that amounts to unchecking,
if myGlobalVariable is, or results in, false.

And that was not what the OP asked for.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top