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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.