# Javascript radio buttons if functions

**URL:** <https://forum.kirupa.com/t/javascript-radio-buttons-if-functions/241251>\
**Category:** Uncategorized\
**Created:** [October 11, 2007, 2:20pm UTC](https://forum.kirupa.com/t/javascript-radio-buttons-if-functions/241251 "2007-10-11T14:20:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arca](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@arca](https://forum.kirupa.com/u/arca)\
**Post date:** [October 11, 2007, 2:20pm UTC](https://forum.kirupa.com/t/javascript-radio-buttons-if-functions/241251/1 "2007-10-11T14:20:21Z")

</div>

This has been plaguing me for days. I cannot figure out why it won’t do like I intend. The //comments are what I would like it to do. Basically I want the $29.99 data plan (“var2”) to be automatically checked if the $39.99 voice plan (“service”) is checked. If anyone can see what I am doing wrong, I’d be grateful.

Below is the code:  
installed in \<head\> section.

\<SCRIPT LANGUAGE=“JavaScript”\>  
\<!-- Begin

function disabler1() { //voice plans checked  
if(document.form.service[0].checked) { //$39.99 voice checked  
document.form.var2[1].checked=true //data $29.99 checked  
document.form.var2[0].checked=false //data $39.99 unchecked  
}  
if(document.form.service[1] { //no voice checked  
document.form.var2[0].checked=true //data $39.99 checked  
document.form.var2[1].checked=false //data $29.99 unchecked  
}  
}

function disabler2() { //data plans checked  
if(document.form.var2[1].checked) { //data $29.99 checked  
document.form.service[0].checked=true //voice $39.99 checked  
document.form.service[1].checked=false //no voice unchecked  
}  
if(document.form.var2[0].checked) { //data $39.99 checked  
document.form.service[1].checked=true //no voice checked  
document.form.service[0].checked=false //$39.99 voice checked  
}  
}  
// End --\>  
\</script\>

below is installed in \<body\> section.  
\<form name=“form”\>  
\<p\>  
\<font size=“3” face=“Arial, Helvetica, sans-serif”\>\<b\>VOICE PLANS\</b\>\</font\>\<br\>  
\<input type=“radio” name=“service” value=“Get More $39.99” onclick=“disabler1()”\>\<a onclick=“document.form.service[‘0’].click();return false”\>\<font size=“3” face=“Arial, Helvetica, sans-serif”\>\<b\>$39.99/month:\</b\>\</font\>\</a\>\<br\>  
\<font size=“2”\>\<b\>Get More\<br\>\</b\>  
600 Whenever minutes per month\<br\>  
Unlimited Weeknight and Weekend minutes  
\</p\>  
\<p\>  
\<input type=“radio” name=“service” value=“No voice plan” onclick=“disabler1()”\>\<a onclick=“document.form.service[‘1’].click();return false”\>\<font size=“3” face=“Arial, Helvetica, sans-serif”\>\<b\>$0.00\</b\>\</font\>\</a\>  
\<br\>  
\<font size=“2”\>No voice plan. You must select the $39.99/month BlackBerry Data-Only Plan\</font\>  
\</p\>

\<p\>\<hr\>\</p\>

\<p\>  
\<font size=“3” face=“Arial, Helvetica, sans-serif”\>\<b\>DATA PLANS\</b\>\</font\>\<br\>  
\<input type=“radio” name=“var2” value=“BB data-only $39.99” onclick=“disabler2()”\>\<a onclick=“document.form.var2[‘0’].click();return false”\>\<font size=“3” face=“Arial, Helvetica, sans-serif”\>\<b\>$39.99/month\</b\>\</font\>\</a\>\<br\>  
\<font size=“2” face=“Arial,Helvetica,Geneva,Swiss,SunSans-Regular”\>\<b\>No voice plan\<br\>\</b\>  
\<font size=“2” face=“Arial,Helvetica,Geneva,Swiss,SunSans-Regular”\>\<b\>BlackBerry Data-Only Plan\<br\>\</b\>\</font\>  
\<font face=“Arial, Helvetica, sans-serif” size=“2”\>Unlimited BlackBerry data usage.\</font\>  
\</p\>  
\<p\>  
\<input type=“radio” name=“var2” value=“unlimited bb data $29.99” onclick=“disabler2()”\>\<a onclick=“document.form.var2[‘1’].click();return false”\>\<font size=“3” face=“Arial, Helvetica, sans-serif”\>\<b\>$29.99/month\</b\>\</font\>\</a\>\<br\> \<font size=“2”\>\<b\>Unlimited BlackBerry Data Add-on\<br\>\</b\>  
Unlimited BlackBerry data usage add-on to a voice plan.\</font\>  
\</p\>  
\</form\>
