Redirect with javascript

K

KL

Is there a way to redirect with javascript? I used javascript to do
some validation on a form, but the form was set to redirect back to the
index page after the submit button was clicked. So what I want to do
is to say if it passes validation, then redirect, but if it doesn't
pass, I want it to stay on the page so the user can fix the problems
and click submit again. Can I even do this in javascript?
 
M

Marc

KL said:
Is there a way to redirect with javascript? I used javascript to do
some validation on a form, but the form was set to redirect back to the
index page after the submit button was clicked. So what I want to do
is to say if it passes validation, then redirect, but if it doesn't
pass, I want it to stay on the page so the user can fix the problems
and click submit again. Can I even do this in javascript?

function validate(){
if (it_validated){
return true
}else{
alert("You forgot to fill out....");
return false
}
}

<form action="the_index_page.php" method="post" onsubmit="return
validate()">
<input type="submit" value="submit">
</form>
 
K

KL

Marc said:
function validate(){
if (it_validated){
return true
}else{
alert("You forgot to fill out....");
return false
}
}

<form action="the_index_page.php" method="post" onsubmit="return
validate()">
<input type="submit" value="submit">
</form>

Thanks for replying Mark, but I am confused. If I use the action in
this manner...how do I get the information that was submitted on the
form to me? As it stands right now, my hosting service has my using
action="gdform.asp" and that makes it email me the information
collected on my form.
 
M

Marc

Thanks for replying Mark, but I am confused. If I use the action in
this manner...how do I get the information that was submitted on the
form to me? As it stands right now, my hosting service has my using
action="gdform.asp" and that makes it email me the information
collected on my form.

Now you got me confused...
You want to access the information from javascript?

function validate(){
if (document.getElementById("info1").value == "" &&
document.getElementById("info1").value == ""){
alert("You forgot to fill out info1 and info2");
return false
}else{
return true
}
}

<form action="gdform.asp" method="post" onsubmit="return validate()">
<input type="text" id="info1" name="info1" value"the information">
<input type="text" id="info2" name="info2" value"more information...">

<input type="submit" value="submit">
</form>
 
K

KL

Marc said:
Now you got me confused...
You want to access the information from javascript?

function validate(){
if (document.getElementById("info1").value == "" &&
document.getElementById("info1").value == ""){
alert("You forgot to fill out info1 and info2");
return false
}else{
return true
}
}

<form action="gdform.asp" method="post" onsubmit="return validate()">
<input type="text" id="info1" name="info1" value"the information">
<input type="text" id="info2" name="info2" value"more information...">

<input type="submit" value="submit">
</form>

Getting closer...but I need to know how to validate a radio button or
checkbox. I tried a few different (but obviously wrong) methods. I am
able to validate text, but how do I validate that darned checkbox to be
sure that they check it? Like when you check boxes or radio buttons to
agree to something online?
 
M

Marc

Now you got me confused...
Getting closer...but I need to know how to validate a radio button or
checkbox. I tried a few different (but obviously wrong) methods. I am
able to validate text, but how do I validate that darned checkbox to be
sure that they check it? Like when you check boxes or radio buttons to
agree to something online?

if (document.getElementById("radio1").checked == false &&
document.getElementById("radio2").checked == false){
alert("puhlease 'validate'..."); return false
}

works the same with checkboxes... the checked property could give you
either true or false...
 
K

KL

Marc said:
if (document.getElementById("radio1").checked == false &&
document.getElementById("radio2").checked == false){
alert("puhlease 'validate'..."); return false
}

works the same with checkboxes... the checked property could give you
either true or false...

OK but now back to the original problem, how do I get it to redirect if
the validation succeeds, or stay on the form if the validation fails?
 
M

Marc

OK but now back to the original problem, how do I get it to redirect if
the validation succeeds, or stay on the form if the validation fails?

What have you tried so far and what isn't working? did you see the alert?
 
K

KL

Marc said:
What have you tried so far and what isn't working? did you see the alert?

Yes I see the alert...here is part of what I have, I tried taking out
the last line, but then it just tries to jump to the main index page
even though it failed the validation....which is not what I want to
have happen at this time...so, how do I redirect AFTER the validation
is true. I don't want people to have to come back and refill in all
the information...I know it would make me madder than a wet hen to have
to do that!

<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.")
submitOK="false"
}
if (submitOK=="false")
{
return false
}

}
</script>

</HEAD>
<BODY bgcolor="#3867AD">

<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" />
 
M

Marc

Yes I see the alert...here is part of what I have, I tried taking out
the last line, but then it just tries to jump to the main index page
even though it failed the validation....which is not what I want to
have happen at this time...so, how do I redirect AFTER the validation
is true. I don't want people to have to come back and refill in all
the information...I know it would make me madder than a wet hen to have
to do that!

a wet hen? omg...

<script type="text/javascript">
function validate(){
if (document.getElementById("CCAcknowledgement").checked==false){
alert ("To process your information, you must acknowledge that your credit
report will be verified and analyzed. Please check the appropriate box.");
return false
}
}
</script>

false is something else then "false"
also False is something different.. be carefull with that... ;)

<form method="post" action="gdform.asp" name="Miniapp"
onsubmit="return validate();">

Notice the return in there?
 
K

KL

Marc said:
a wet hen? omg...

<script type="text/javascript">
function validate(){
if (document.getElementById("CCAcknowledgement").checked==false){
alert ("To process your information, you must acknowledge that your credit
report will be verified and analyzed. Please check the appropriate box.");
return false
}
}
</script>

false is something else then "false"
also False is something different.. be carefull with that... ;)



Notice the return in there?

OK so first off I need to use "" around false in the javascript part.
And onsubmit will be either false or true because of the return, right?
I guess I don't see what I should be doing different there.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sun, 16 Jul 2006 09:01:14 remote, seen in
Marc said:
function validate(){
if (it_validated){
return true
}else{
alert("You forgot to fill out....");
return false
}
}

There's no need for an else after an if...return :

function validate() {
if (it_validated) return true
alert("You forgot to fill out....");
return false }

In English, that should be "... fill in ..."; "fill out" is American.

You could probably omit return false but it's good to have it visible.

Elsewhere in thread :
== true Can be removed
== false Nicer to use the ! operator
 
K

KL

Dr said:
JRS: In article <[email protected]>, dated
Sun, 16 Jul 2006 09:01:14 remote, seen in

There's no need for an else after an if...return :

function validate() {
if (it_validated) return true
alert("You forgot to fill out....");
return false }

In English, that should be "... fill in ..."; "fill out" is American.

You could probably omit return false but it's good to have it visible.

Elsewhere in thread :
== true Can be removed
== false Nicer to use the ! operator

Yes, Dr. Stockton, my American is showing...but that is ok, cause I
always tease my friend in England that her English is showing when she
uses 's' for 'z'...she says us bloody Yanks can't spell!!

I didn't know about not needing the else when using an if....return. I
just tend to use else so I remember and see what I was meaning/doing.

Will try these changes, but I still don't see how that will correct my
redirect problem....sometimes I can be a bit dense! LOL
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top