Jump to content

[SOLVED] submit button remain disabled until checkbox checked?


argan328

Recommended Posts

Hi!

I picked this script up from a posting here over a year ago and it's exactly what I need...the submit button is supposed to be disabled until the user checks the box that he/she has read the terms of use... the problem is that if the user clicks on the submit button it becomes enabled along with the check box at the same time.  I want the submit button to remain disabled until the user specifically clicks on the checkbox.

 

<script language="javascript">
    function Activate()
        {
            check_box = document.getElementById('checkbox');
            button = document.getElementById('Submit'); 
             
            if ( check_box.checked == true )
                {
                    button.disabled = false;
                }
            else
                button.disabled = true;
        }

</script>


<form id="form1" name="form1" method="post" action="">
  <label> 
  <input type="checkbox" name="checkbox" id="checkbox" value="0" onClick="Activate()"/>
  <br />
  <input type="submit" name="Submit" id='Submit' value="Submit" disabled />
  </label>
</form>

 

Can anyone help?

forgive me I'm still a newbie, by "make the submit a class do you mean something like this:

 

submit {

visibility:hidden

}

 

or

 

<STYLE> .vis1 { visibility:visible } .vis2 { visibility:hidden } </STYLE>

 

and then how would I set it to visibility:visible in my Activate function?

Thanks

Argan

Here's my "off the cuff" solution:

<script type="text/javascript">
function checkSubmit(ele, id) {
x = document.getElementById(id);
if (ele.checked == true) x.disabled = false;
else x.disabled = true;
}
</script>

<input type="checkbox" name="myCheck" onclick="checkSubmit(this, 'mySubmit')" value="y" />
<input type="submit" name="submit" value="Submit" id="mySubmit" disabled="disabled" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.