By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

Stop a redirect if not validated

P: n/a
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.fo cus()">
<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>

Jul 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 21 '06 #2

P: n/a
KL
Randy Webb wrote:
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".
I added the 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.
My bad...I took it out, but forgot that one spot
>
if (test==false)

if (!test)

test it.
got that now
>
{
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.
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!
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 21 '06 #3

P: n/a
KL said the following on 7/21/2006 12:38 AM:
Randy Webb wrote:
>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".

I added the 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.

My bad...I took it out, but forgot that one spot
Actually, I used the wrong word. Not parentheses, but quotation marks.
>>if (test==false)
if (!test)

test it.

got that now
>>{
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.

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.
>> }
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
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
>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!
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.