|
|
Subject:
Multiple onSubmit Functions
Category: Computers > Programming Asked by: therhino-ga List Price: $20.00 |
Posted:
22 May 2006 08:17 PDT
Expires: 21 Jun 2006 08:17 PDT Question ID: 731289 |
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. |
|
Subject:
Re: Multiple onSubmit Functions
Answered By: palitoy-ga on 22 May 2006 09:30 PDT Rated: |
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
rated this answer:
Spot on, thanks |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |