Forums

Disable submit button

laurie 06 Jul, 2012
Hi

I am trying to disable the submit button on my form, until a tick box is checked but it is not working properly.

The Submit button is disabled at the start of the form loading, but does not enable when the checkbox is clicked.

Can anyone see what I am doing wrong ?

Here is the code placed in the onload JS code
// stop the code executing 
// until the page is loaded in the browser
window.addEvent('load', function() { 
// function to enable and disable the submit button  
function agree() {
    if ( $('terms00').checked == true ) {
      $('submit').disabled = false;
  alert('checked!');  
} else {      
      $('submit').disabled = true;
   alert('Not checked!'); 
}  
};  
// disable the submit button on load  
$('submit').disabled = true;  
//execute the function when the checkbox is clicked  $('terms00').addEvent('click', agree);
});


Thanks Laurie
GreyHead 06 Jul, 2012
Hi Laurie,

It looks as though the code to execute onClick may be in the comment, try putting it on a new line.

Bob
laurie 06 Jul, 2012
Hi Bob

In th java scritp window it is on a new line. Not sure why it copied in like that.

Put it on a new line anyway, but made no difference.

On the same site as my other issues if you need to see what its not doing.

Cheers
Laurie
GreyHead 07 Jul, 2012
Hi Laurie,

The ID of the checkbox isn't terms00
<input type="checkbox" name="terms00[]" id="terms00_0" title="" value="agree">


You can use your web browser developer tools to check the JavaScript console and explore the page source to debug problems like this.

Bob
laurie 07 Jul, 2012
Hi Bob

Did notice that and change it to terms00_0 but it made no difference so thought I was reading it wrong. I will change it back and try again.

On thing that did occur to me is if I have the code in the wrong place. I have it in the onload. Does this mean the code will only run once on the loading of the form. For this to work it would have to run all the time to detect the change. Also does the page have to be automatically updated in some way for the change to show.

Regards
Laurie
GreyHead 07 Jul, 2012
Hi Laurie,

It seems to be working OK in Chrome now?

Bob
laurie 07 Jul, 2012
Hi Bob

Yes did what you said. Strange but I had tried that earlier, but this time cleared the browser cache. Worked fine then.

Just looking into a way of clearing the verification bubble from the screen when you click to a different tab, then hopefully almost done on this form. Max found the problem with the verification bubble being in the wrong place, but not yet why the verification is not working on the radio buttons.

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