Disable Submit Button unless certain buttons are checked?

jk jkerr 08 Dec, 2010
Hi all

Carrying on from my previous thread, I now need to have the submit button disabled unless certain radio buttons are checked (all questions answered yes).

The code I have now is

function enablebutton()
{
if (document.ChronoContact_FundingChecklist.radio00.checked==true && document.ChronoContact_FundingChecklist.radio10.checked==true);
{
document.ChronoContact_FundingChecklist.button_8.disabled=false
}
}


Plus onclick="enablebutton()" for radio00 and radio10.

However, this enables button_8 if either radio00 is checked or radio10 is checked, rather than them both together. Any help would be appreciated.

Cheers
Jamie
Gr GreyHead 13 Dec, 2010
Hi jamie,

Here's how I would write it - switched into MooTools syntax:
window.addEvent('domready', function() {
  $('radio00').addEvent('click', enableButton);
  $('radio10').addEvent('click', enableButton);
});
function enableButton()
{
  if ( $('radio00').checked == true && $('radio10').checked == true ) {
    $('button_8').disabled = false;
  } else {
    $('button_8').disabled = true;
  }
;}

Bob
jk jkerr 14 Dec, 2010
Thanks for your help. I managed to sort it myself using a gigantic if statement.


function enablebutton()

{
if ((document.ChronoContact_FundingChecklist.radio0[0].checked==true) && (document.ChronoContact_FundingChecklist.radio1[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio2[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio3[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio4[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio5[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio6[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio7[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio8[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio9[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio100.checked==true) &&
(document.ChronoContact_FundingChecklist.radio110.checked==true) &&
(document.ChronoContact_FundingChecklist.radio12[0].checked==true) &&
(document.ChronoContact_FundingChecklist.radio13[0].checked==true))
{
document.ChronoContact_FundingChecklist.button_8.disabled=false
}
}

function disablebutton()

{
document.ChronoContact_FundingChecklist.button_8.disabled=true
}


onclick="enablebutton" for yes answers and onclick="disablebutton" for when no is selected. No idea how efficient this is but it does the job.

Cheers.
This topic is locked and no more replies can be posted.