Urgent Help - How to redirect multiple page from a single html form using JS validati

Discussion in 'JavaScript' started by foodrecipe, Aug 8, 2012.

  1. #1
    Hi

    I have the following form

    <form action="index.html" id="target">
    <label>Email</label>
    <input id="email" type="text" name="name" required" />

    <label">Password</label>
    <input id="pass" type="password" name="name" required" />
    <button onclick="return ">Login</button>
    <button>Cancel</button>
    </div>
    </form>

    When user types "login" & "success" as a username and pass then only it should redirect to another page else not. That was the condition. And when he type "login" & "getin" it should redirect to another page.

    I have done this


    script type="text/javascript">


    $('#target').submit(function() {
    var email = $('#email').val();
    var pass = $('#pass').val();
    if((email == "login") && (pass == "success")){
    return true;
    }
    else{
    return false;
    }
    });


    It redirects to a single page. But cant able to get the second one. even i tried with window.alert.

    Please help me.

    Thanks
     
    foodrecipe, Aug 8, 2012 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    You can try window.location.replace method.
    Instead of returning true/false from ur javascript, you can redirect to the required page.

    
    // similar behavior as an HTTP redirect
    window.location.replace("http://scriptsplash.com");
    
    // similar behavior as clicking on a link
    window.location.href = "http://scriptsplash.com";
    
    Code (markup):
    Here's the jQuery Alternative

    
    var url = "http://scriptsplash.com";    
    $(location).attr('href',url);
    
    Code (markup):
     
    Last edited: Aug 9, 2012
    Unni krishnan, Aug 9, 2012 IP