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

Redirect with javascript

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

--
KL

Jul 16 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a

"KL" <kl*******@gmail.comschreef in bericht
news:11********************@p79g2000cwp.googlegrou ps.com...
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?

--
KL
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>
Jul 16 '06 #2

P: n/a
KL

Marc wrote:
"KL" <kl*******@gmail.comschreef in bericht
news:11********************@p79g2000cwp.googlegrou ps.com...
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?

--
KL

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.

--
KL

Jul 16 '06 #3

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

--
KL
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>
Jul 16 '06 #4

P: n/a
KL

Marc wrote:

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.

--
KL

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?

--

KL

Jul 16 '06 #5

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

--

KL
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...


Jul 16 '06 #6

P: n/a
KL

Marc wrote:
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?

--

KL

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?

--
KL

Jul 16 '06 #7

P: n/a
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?
Jul 16 '06 #8

P: n/a
KL

Marc wrote:
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?
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" />

Jul 16 '06 #9

P: n/a
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").chec ked==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?
Jul 16 '06 #10

P: n/a
KL

Marc wrote:
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").chec ked==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?
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.

--

KL

Jul 16 '06 #11

P: n/a
JRS: In article <19***************************@news.chello.nl>, dated
Sun, 16 Jul 2006 09:01:14 remote, seen in news:comp.lang.javascript,
Marc <so******@spam.composted :
>
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

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 16 '06 #12

P: n/a
KL

Dr John Stockton wrote:
JRS: In article <19***************************@news.chello.nl>, dated
Sun, 16 Jul 2006 09:01:14 remote, seen in news:comp.lang.javascript,
Marc <so******@spam.composted :

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

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
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

--

KL

Jul 16 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.