![]() |
Disable Submit Button until Accept Terms and Redirect Page on Submit
The script below will disable Submit button until user accept terms,
and will redirect user to another page after clicking on Submit button. The script seems to work fine on my PC (Windows XP, IE6), however I don't know if it's written well. I would like the opinion of someone who knows how to write these codes properly. Please let me know if there're any logic errors. PS: Please keep in mind that I didn't write this script, I found it over the internet. Therefore do not make me responsible for (1) copyright, (2) any damage this script may cause, (3) incompatibility, (4) bugs this script may have. Here's my entire page: <html> <head> <script> var checkobj function agreesubmit(el){ checkobj=el if (document.all||document.getElementById){ for (i=0;i<checkobj.form.length;i++){ //hunt down submit button var tempobj=checkobj.form.elements[i] if(tempobj.type.toLowerCase()=="submit") tempobj.disabled=!checkobj.checked } } } function defaultagree(el){ if (!document.all&&!document.getElementById){ if (window.checkobj&&checkobj.checked) return true else{ alert("Please Read/Accept our Terms of Service/Agreement to continue.") return false } } } </script> <SCRIPT LANGUAGE="JavaScript"> var destination="redirectingpage.htm"; function redirect() { window.location = destination; } // End --> </script> </head> <body> <form method="post" name=agreeform onSubmit="return defaultagree(this)" action="javascript:redirect()"> <iframe name="agreement" src="email/agreement.htm" border="0" frameborder="0" marginwidth="3" marginheight="3" width="600" height="110" style="border: 3px solid #294A63"> Your browser does not support inline frames or is currently configured not to display inline frames.</iframe></p> <input name="agreecheck" value="agree" type="checkbox" onClick="agreesubmit(this)">I Agree to the above Terms of Service/Agreement<br> <input type="Submit" value="Continue" disabled></form> <script> document.forms.agreeform.agreecheck.checked=false </script> </body> </html> |
Re: Disable Submit Button until Accept Terms and Redirect Page on Submit
In article <195dfbe4.0309091924.400e2998@posting.google.com >,
flash12345flash@hotmail.com (Paul Oakfleet) wrote: > ... > The script seems to work fine on my PC (Windows XP, IE6), however I > don't know if it's written well. I would like the opinion of someone > who knows how to write these codes properly. Please let me know if > there're any logic errors. > > PS: Please keep in mind that I didn't write this script, I found it > over the internet. > Here's my entire page: > > <html> > <head> > <script> Should be <script language="javascript"> or for modern browsers <script type="text/javascript"> > > var checkobj not needed > > function agreesubmit(el){ > checkobj=el > if (document.all||document.getElementById){ > for (i=0;i<checkobj.form.length;i++){ //hunt down submit button > var tempobj=checkobj.form.elements[i] > if(tempobj.type.toLowerCase()=="submit") > tempobj.disabled=!checkobj.checked > } > } > } No search needed. Just give the Submit button a name, e.g., "submitter" (don't call it "submit"!). Then you can write function agreesubmit(checkobj) { checkobj.form.submitter.disabled = !checkobj.checked; } > function defaultagree(el){ > if (!document.all&&!document.getElementById){ > if (window.checkobj&&checkobj.checked) > return true > else{ > alert("Please Read/Accept our Terms of Service/Agreement to > continue.") > return false > } > } > } I don't know what that outer IF is for, and window.checkobj looks bogus to me. Also el (for element?) is a poor name, given it's really the form. Better code would be function defaultagree(form) { if (!form.agreecheck.checked) { alert(Please Read/Accept our Terms of Service/Agreement to continue."); } return form.agreecheck.checked; } > > </script> > <SCRIPT LANGUAGE="JavaScript"> drop these two lines. Why close the script element just to restart it? > > var destination="redirectingpage.htm"; > > function redirect() > { > window.location = destination; > } > > // End --> > </script> > </head> > <body> > <form method="post" name=agreeform onSubmit="return > defaultagree(this)" action="javascript:redirect()"> > <iframe name="agreement" src="email/agreement.htm" border="0" > frameborder="0" marginwidth="3" marginheight="3" width="600" > height="110" style="border: 3px solid #294A63"> > Your browser does not support inline frames or is currently configured > not to display inline frames.</iframe></p> there's no <p> for this </p> > <input name="agreecheck" value="agree" type="checkbox" > onClick="agreesubmit(this)">I Agree to the above Terms of > Service/Agreement<br> > <input type="Submit" value="Continue" disabled></form> add name="submitter" to this <input> > <script> > document.forms.agreeform.agreecheck.checked=false > </script> > </body> > </html> |
| All times are GMT. The time now is 04:29 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.