Stop a redirect if not validated

K

KL

I am trying to get a form to work with validating a checkbox. It
validates the checkbox ok, but it always redirects, even if the box
isn't checked...it does alert, but I was hoping that it would stay on
the current page and not redirect unless the box IS checked. I really
can't see what I did wrong. Any and all help would be appreciated.

My code so far is:

<HTML>
<HEAD>
<TITLE>Application</TITLE>
<script type="text/javascript">

function validate()
{

var test=document.getElementById("CCAcknowledgement").checked
submitOK="true"


if (test==false)
{
alert ("To process your information, you must acknowledge that your
credit report will be verified and

analyzed. Please check the appropriate box.")

}

{
window.navigate('index3.html');
}

</script>


</HEAD>
<BODY bgcolor="#3867AD"
onLoad="self.focus();document.Miniapp.FirstName.focus()">
<CENTER>
TEST OF APPLICATION LINK
</CENTER>
<CENTER><TABLE BORDER="0" WIDTH="500"><TD>
<FORM METHOD="POST" ACTION="gdform.asp" name="Miniapp"
ONSUBMIT="validate();">
<input type="hidden" name="subject" value="Application Submission" />
<input type="hidden" name="redirect" value="index3.html" />

<p> </p>
<FIELDSET>
<LEGEND><b>Step Three: Credit Check Acknowledgement</b></LEGEND>
<p><INPUT TYPE="checkbox" id="CCAcknowledgement"
onclick="ToggleCheck()"

name="CCAcknowledgement"><font size="5">Testing of
Acknowledgement.</font></p>
</FIELDSET>
</TD></TABLE>

</CENTER>
<center><input type="submit" value="Submit" /> <INPUT
TYPE="reset"></center>
</form>
</BODY>
</HTML>
 
R

Randy Webb

KL said the following on 7/20/2006 10:31 PM:
I am trying to get a form to work with validating a checkbox. It
validates the checkbox ok, but it always redirects, even if the box
isn't checked...it does alert, but I was hoping that it would stay on
the current page and not redirect unless the box IS checked. I really
can't see what I did wrong. Any and all help would be appreciated.

You left out the word "else".
My code so far is:

<HTML>
<HEAD>
<TITLE>Application</TITLE>
<script type="text/javascript">

function validate()
{

var test=document.getElementById("CCAcknowledgement").checked
submitOK="true"

What is submitOK used for? And, if you are using it as a Boolean, it
should be submitOK = true, without the parentheses.
if (test==false)

if (!test)

test it.
{
alert ("To process your information, you must acknowledge that your
credit report will be verified and

analyzed. Please check the appropriate box.")

}

Here is where the word "else" is missing.
{
window.navigate('index3.html');

window.navigate shouldn't be used. Set the location property.

Here, there is a closing } missing.

It is totally surprising that you get an alert from that code.

Have the function return test. If it is true, then the form gets
submitted. If it is false, the form won't get submitted.

And what is with all the HTML3.2 code?

There is more that could be said about it, but that is enough to get you
started.
 
K

KL

Randy said:
KL said the following on 7/20/2006 10:31 PM:

You left out the word "else".

I added the else...
What is submitOK used for? And, if you are using it as a Boolean, it
should be submitOK = true, without the parentheses.

My bad...I took it out, but forgot that one spot
if (!test)

test it.

got that now
Here is where the word "else" is missing.


window.navigate shouldn't be used. Set the location property.

I do not understand what you mean here. I am new to Javascript.
Here, there is a closing } missing.

It is totally surprising that you get an alert from that code.

Have the function return test. If it is true, then the form gets
submitted. If it is false, the form won't get submitted.

And what is with all the HTML3.2 code?

Heh, I haven't had the time yet to learn 4.0 ... and I am self taught
for 3.2
There is more that could be said about it, but that is enough to get you
started.

Don't be shy! I really do want to know where I am going wrong...I
won't learn if my mistakes aren't pointed out to me! And I appreciate
your time and efforts to help me!
 
R

Randy Webb

KL said the following on 7/21/2006 12:38 AM:
I added the else...

My bad...I took it out, but forgot that one spot

Actually, I used the wrong word. Not parentheses, but quotation marks.
got that now


I do not understand what you mean here. I am new to Javascript.

Well, actually, you shouldn't be using either for what you are doing.
Have the function validate the form. If it should be submitted, return
true. Otherwise, return false. Then, the form gets submitted or they
stay where they are.

But, to answer you, you set the location property:

document.location = "someWhere.html";

or:

window.location = "someWhere.html";

Which you use depends on what navigation you want to take place. In a
non-frameset, they do the same thing. In a frameset they don't do the
same thing.
Heh, I haven't had the time yet to learn 4.0 ... and I am self taught
for 3.2

Forget HTML3.2, learn HTML4.01 (at a minimum) with CSS. It will make
your life a lot simpler.

For questions about them:

HTML: comp.infosystems.www.authoring.html
CSS: comp.infosystems.www.authoring.stylesheets
Don't be shy! I really do want to know where I am going wrong...I
won't learn if my mistakes aren't pointed out to me! And I appreciate
your time and efforts to help me!

One thing I don't think I could ever be accused of is being shy.

Fix the errors already shown, then post back with a URL to a sample
page. The critiques around here are endless.
 

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

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top