•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,234 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,762 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2900 | Replies: 5 | Solved
![]() |
•
•
Join Date: Sep 2005
Location: St. Louis
Posts: 145
Reputation:
Rep Power: 4
Solved Threads: 0
I'm trying to create a page that has a button at the end with a check box before it. Unless the check box is checked, it shouldn't carry through with the link. I absolutely cannot get it to work. I've been toying around with it for over a half hour now and can't get it working. I'm not sure that I actually need the <form> elements in there since it's not actually a form, but I can't begin to conceive how to make it work without the <form> elements, though. Here's what I've come up with at this point:
<!accept.html>
<html>
<head><title>Agreement Page</title>
<script type="text/javascript">
<!-- HIDE FROM IMCOMPATIBLE BROWSERS
function submitForm() {
var submitForm = false;
if (document.forms[0].accept.value == "")
window.alert("You must agree with the above items in order to utilize the statistics form.");
return false;
else {
return true;
}
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script></head>
<body bgcolor="#CCCCCC">
<p><div align="center"><font size="4" face="Garramond">Before you go any further, you need to read the following and agree to it.<br />Otherwise, you cannot utilize the statistics form.</font></div></p><br /><br />
<p><font size="2" face="Arial">
<ul>
<li>These pages have been developed for educational purposes only.</li>
<li>No profit is intended to be made.</li>
<li>The images contained herein are property of the National Football Leauge, the NFL Players Association, and the Dallas Cowboys.<br />The use of them is not intended as copyright infringement.</li>
<li>These pages are not intended to aid or promote illegal gambling. By using them, you (the user) will not try and accomplish this means.</li>
</ul>
</font></p><br /><br />
<p>Do you accept the terms as outlined above?<br />
<form action="" method="post" onsubmit="return confirmSubmit();">
<input type="checkbox" name="accept" value="Accepted" />I Accept<br /><br />
<input type="button" name="proceed" value="Proceed" onclick=window.location="nflStats.html";>
</form></p>
</body>
</html>•
•
Join Date: Mar 2007
Location: Brisbane, Australia
Posts: 215
Reputation:
Rep Power: 2
Solved Threads: 13
move you window redirecting code to a javascript function. Make your onclick call a function to validate the checkbox (again, in javascript), and then if the checkbox is checked you can then redirect.
Actually looking at your code, you seem to be mixing 2 approaches. You do not actually need the onclick if you set the input type to "submit" and the form action to "nflStats.html". Using this will trigger your confirmSubmit function too.
So there are 2 approaches you can take, I suggest you take the latter one I have mentioned.
Actually looking at your code, you seem to be mixing 2 approaches. You do not actually need the onclick if you set the input type to "submit" and the form action to "nflStats.html". Using this will trigger your confirmSubmit function too.
So there are 2 approaches you can take, I suggest you take the latter one I have mentioned.
•
•
Join Date: Sep 2005
Location: St. Louis
Posts: 145
Reputation:
Rep Power: 4
Solved Threads: 0
I made some changes and it is still loading nflStats.html whether the check box is checked or not. Here is what I have right now:
Where do I seem to be dropping the ball at on this one?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtmll-transitional.dtd">
<!--accept.html-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Agreement Page</title>
<script type="text/javascript">
<!-- HIDE FROM IMCOMPATIBLE BROWSERS
function confirmSubmit() {
var submitForm = false;
if (document.forms[0].accept.value == "")
window.alert("You must agree with the above items in order to utilize the statistics form.");
return false;
else {
return true;
}
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script></head>
<body bgcolor="#CCCCCC">
<p><div align="center"><font size="4" face="Garramond">Before you go any further, you need to read the following and agree to it.<br />Otherwise, you cannot utilize the statistics form.</font></div></p><br /><br />
<p><font size="2" face="Arial">
<ul>
<li>These pages have been developed for educational purposes only.</li>
<li>No profit is intended to be made.</li>
<li>The images contained herein are property of the National Football League, the NFL Players Association, and the Dallas Cowboys.<br />The use of them is not intended as copyright infringement.</li>
<li>These pages are not intended to aid or promote illegal gambling. By using them, you (the user) will not try and accomplish this means.</li>
</ul>
</font></p><br /><br />
<p>Do you accept the terms as outlined above?<br />
<form action="nflStats.html" method="post" onsubmit="return confirmSubmit();">
<input type="checkbox" name="accept" value="Accepted" />I Accept<br /><br />
<input type="submit" name="proceed" value="Proceed">
</form></p>
</body>
</html>Where do I seem to be dropping the ball at on this one?
•
•
Join Date: Mar 2007
Location: Brisbane, Australia
Posts: 215
Reputation:
Rep Power: 2
Solved Threads: 13
Watch your blocks as I think you are missing a few { }.
I would do it slightly different to you, but this is how I would do it:
For this to work with your code, just make sure you set the id for your checkbox to "accept".
I would do it slightly different to you, but this is how I would do it:
function confirmSubmit() {
var acc = document.getElementById("accept");
if (!acc.checked) {
alert("You must agree with the above items in order to utilize the statistics form.");
return false;
} else {
return true;
}
}For this to work with your code, just make sure you set the id for your checkbox to "accept".
var acc = document.getElementById('accept') assigns the reference of the checkbox element of your form to acc. Checkboxes have a property checked which determines whether a checkbox is checked or not. Thus
!acc.checked means 'when checkbox is not checked'. I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Problem about my check box ! (PHP)
- I have problem with check box (PHP)
- "Validating select box text" (PHP)
- Problem in Default Value of Check Box (JavaScript / DHTML / AJAX)
- tree control view with check box (C#)
- check box (ASP)
- Cannot enter any text in a IE text-box (Viruses, Spyware and other Nasties)
- Re: Check for Disk Errors in Windows XP (Windows NT / 2000 / XP / 2003)
- Check for Disk Errors in Windows XP (Windows tips 'n' tweaks)
- IE6 - dialogue boxes , check boxes and radio buttons work very slowly after hijacking (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Submitting data before auto-refresh
- Next Thread: Iframe inside close - Is there a better way?



Linear Mode