Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2005, 04:38 AM   PM User | #1
ImperialSpider
Regular Coder

 
Join Date: Jan 2004
Location: San Antonio, TX
Posts: 131
Thanks: 1
Thanked 0 Times in 0 Posts
ImperialSpider is an unknown quantity at this point
need help with a submission form

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.
ImperialSpider is offline   Reply With Quote
Old 01-28-2005, 04:47 AM   PM User | #2
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Well once you have checked the form validity, just do:
Code:
location='page1.html';
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 01-28-2005, 08:18 AM   PM User | #3
ImperialSpider
Regular Coder

 
Join Date: Jan 2004
Location: San Antonio, TX
Posts: 131
Thanks: 1
Thanked 0 Times in 0 Posts
ImperialSpider is an unknown quantity at this point
Thanks, but...

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.
ImperialSpider is offline   Reply With Quote
Old 01-28-2005, 10:58 AM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Copy and paste this:
Code:
<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>
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app

Last edited by glenngv; 01-28-2005 at 11:00 AM..
glenngv is offline   Reply With Quote
Old 01-28-2005, 09:40 PM   PM User | #5
ImperialSpider
Regular Coder

 
Join Date: Jan 2004
Location: San Antonio, TX
Posts: 131
Thanks: 1
Thanked 0 Times in 0 Posts
ImperialSpider is an unknown quantity at this point
Thumbs up Thank you

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.
ImperialSpider is offline   Reply With Quote
Old 01-29-2005, 03:31 AM   PM User | #6
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Well the reason for that is the syntax of your conditional statement:
Code:
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:
Code:
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.
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:50 AM.


Advertisement
Log in to turn off these ads.