PDA

View Full Version : need help with a submission form



ImperialSpider
01-28-2005, 04:38 AM
What I am wanting is this...once the user checks the box, and clicks submit...the prompt comes up with an 'OK' button. I want the user to be redirected to "\page1.html" when they click that 'OK' button. What do I need to do, or what do I need to change in my code???

Below is the code I am using:

<html><title>agreement form</title>
<P>
<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 (window.checkobj&&checkobj.checked)
alert("Great, Lets get started.")
else
alert("Please check the box if your agree to the conditions")
return false
}
</script>
<BODY BGCOLOR="#00FFFF">
<form name="agreeform" onSubmit="return defaultagree(this)">
YOU MUST MEET MY CONDITIONS, WHICH ARE...<br><br>
<textarea rows="5" name="S1" cols="30" style="width:60%" wrap=virtual>
1. FIRST CONDITION.
2. SECOND CONDITION.
3. THIRD CONDITION.
4. FOURTH CONDITION.
5. FIFTH CONDITION.
6. SIXTH CONDITION.
7. SEVENTH CONDITION.
</textarea><p>
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)">
<b>Check box if you agree to the above conditions</b><p>
<input type="Submit" value="Submit!">
</form>
<script>
document.forms.agreeform.agreecheck.checked=false
</script>
<p><p>
</body></head></html>

Thanks in advance for your help.

Mhtml
01-28-2005, 04:47 AM
Well once you have checked the form validity, just do:


location='page1.html';

ImperialSpider
01-28-2005, 08:18 AM
Thanks, But I am kinda new with Javascript, I apologize for not making that more clear earlier. I copied this script from another website. (using view-source). Where would I put that code location='page1.html'; at within my code? I have tried to put it in several locations, but when I do, it is stopping the rest of the page from working. Also, how do you check the form validity? I am a copy and paste-er and haven't really learned javascript yet, I am getting there though :) Again, Thanks for your help.

glenngv
01-28-2005, 10:58 AM
Copy and paste this:


<html>
<head>
<title>agreement form</title>
<script type="text/javascript">
function agreesubmit(el){
var tempobj;
var els=el.form.elements;
for (var i=0;i<els.length;i++){ //hunt down submit button
tempobj=els[i];
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!el.checked;
}
}
function defaultagree(el){
if (el.agreecheck.checked){
alert("Great, Lets get started.");
location.href='page1.html';
}
else
alert("Please check the box if your agree to the conditions")
return false
}
</script>
</head>
<body>
<form name="agreeform" onSubmit="return defaultagree(this)">
<p>YOU MUST MEET MY CONDITIONS, WHICH ARE...</p>
<textarea rows="5" name="S1" cols="30" style="width:60%" wrap="virtual">
1. FIRST CONDITION.
2. SECOND CONDITION.
3. THIRD CONDITION.
4. FOURTH CONDITION.
5. FIFTH CONDITION.
6. SIXTH CONDITION.
7. SEVENTH CONDITION.
</textarea>
<p>
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)" />
<b>Check box if you agree to the above conditions</b>
<p><input type="Submit" value="Submit!" disabled="disabled" /></p>
</form>
</body>
</html>

ImperialSpider
01-28-2005, 09:40 PM
This worked! It is confusing to me however, because I placed the text (location='page1.html';) in the exact same location you did, and when I clicked the submit button with the checkbox checked, it would act as if I had not checked the box and bring up the prompt to check the box first. I will go over the code to see what the differences are, but I just wanted to thank you for your help.

Imperial Spider.

Mhtml
01-29-2005, 03:31 AM
Well the reason for that is the syntax of your conditional statement:


if( condition ) {
do everything between that bracket and the next
}else{
or do evereything between that bracket and the next
}

It is different without the brackets:


if(condition)
just do the first thing following the condition
else
just do the first thing following the exception


Not sure if that exactly makes sense to you.