Redirect with javascript

Discussion in 'Javascript' started by KL, Jul 16, 2006.

  1. KL

    KL Guest

    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
     
    KL, Jul 16, 2006
    #1
    1. Advertising

  2. KL

    Marc Guest

    "KL" <> schreef in bericht
    news:...
    > 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>
     
    Marc, Jul 16, 2006
    #2
    1. Advertising

  3. KL

    KL Guest

    Marc wrote:
    > "KL" <> schreef in bericht
    > news:...
    > > 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
     
    KL, Jul 16, 2006
    #3
  4. KL

    Marc Guest

    >
    > 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>
     
    Marc, Jul 16, 2006
    #4
  5. KL

    KL Guest

    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
     
    KL, Jul 16, 2006
    #5
  6. KL

    Marc Guest

    >> 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...
     
    Marc, Jul 16, 2006
    #6
  7. KL

    KL Guest

    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
     
    KL, Jul 16, 2006
    #7
  8. KL

    Marc Guest

    > 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?
     
    Marc, Jul 16, 2006
    #8
  9. KL

    KL Guest

    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" />
     
    KL, Jul 16, 2006
    #9
  10. KL

    Marc Guest

    > 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?
     
    Marc, Jul 16, 2006
    #10
  11. KL

    KL Guest

    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").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?


    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
     
    KL, Jul 16, 2006
    #11
  12. JRS: In article <19909$44b9e453$d55d489d$>, dated
    Sun, 16 Jul 2006 09:01:14 remote, seen in news:comp.lang.javascript,
    Marc <> posted :
    >
    >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.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Jul 16, 2006
    #12
  13. KL

    KL Guest

    Dr John Stockton wrote:
    > JRS: In article <19909$44b9e453$d55d489d$>, dated
    > Sun, 16 Jul 2006 09:01:14 remote, seen in news:comp.lang.javascript,
    > Marc <> posted :
    > >
    > >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.htm> jscr 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
     
    KL, Jul 17, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dh
    Replies:
    2
    Views:
    538
  2. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,260
    Srowe1975
    Oct 15, 2008
  3. Replies:
    7
    Views:
    13,119
    justingrant
    Oct 18, 2008
  4. Sal
    Replies:
    1
    Views:
    547
  5. Ron Howard
    Replies:
    2
    Views:
    528
    Ron Howard
    Aug 11, 2004
Loading...

Share This Page