How to disable button when checkbox is checked. vbscript?

Multiple onSubmit Functions

  • I need to add to functions to a form upon submission: 1) I need to make sure the checkbox is ticked 2) If the checkbox is ticked and the form is submitted successfully, I need to disable the submit button to prevent multiple submissions. Here is example code which can be used for the above requirements individually: Checkbox checker ---------------- <!-- function checkCheckBox(hh){ if (hh.accept.checked == false ) { alert('You must accept our Privacy Policy to continue'); return false; }else return true; } //--> <form action="---" method="post" enctype="multipart/form-data" onsubmit="return checkCheckBox(this)"> <input type="checkbox" value="0" name="accept"> Disable submit button code -------------------------- <!-- Begin function disableForm(theform) { if (document.all || document.getElementById) { for (i = 0; i < theform.length; i++) { var tempobj = theform.elements[i]; if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset") tempobj.disabled = true; } } } // End --> <form action="---" method="post" enctype="multipart/form-data" onsubmit="return disableForm(this);"> So, I need a piece of code which combines these 2 functions please.

  • Answer:

    Hello therhino-ga, Thank-you for your question. The easiest way to disable an element on a page is to make sure everything is *named* in the form, by doing this you can then directly reference them. Lets take this form: <form name="form1" action="---" method="post" enctype="multipart/form-data" onsubmit="return checkCheckBox(this)"> <input type="checkbox" value="0" name="accept"> <input name="submitbtn" type="submit" /> </form> This form is called "form1" and has a checkbox called "accept" and a submit button called "submitbtn". Let's look at this piece of javascript: document.form1.submitbtn.disabled=true; This code would disable an element called "submitbtn" in the form called "form1" on the page. To combine this with your example we would be left with an example page like this: <script language="javascript"> function checkCheckBox(hh){ if (hh.accept.checked == false ) { alert('You must accept our Privacy Policy to continue'); return false; } else document.form1.submitbtn.disabled=true; // remove the following line to remove the alert! alert("The Submit button is disabled!"); return true; } //--> </script> <form name="form1" action="---" method="post" enctype="multipart/form-data" onsubmit="return checkCheckBox(this)"> <input type="checkbox" value="0" name="accept"> <input name="submitbtn" type="submit" /> </form> If you require any further assistance with this matter please do not hesitate to ask for clarification and I will do my best to respond swiftly.

therhino-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.