Disable Submit Button until Accept Terms and Redirect Page on Submit

P

Paul Oakfleet

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
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>
 
C

Chris Riesbeck

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.[/QUOTE]
Here's my entire page:

<html>
<head>
<script>

Should be <script language="javascript"> or for modern browsers
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
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top