Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question if JavaScript on submit using JS if JavaScript off submit using standard submit

    Hello Everybody

    I need help to making code

    I have form and I want to send data to php page by Ajax but if JavaScript enable submit Form using JavaScript code if JavaScript disable submit form using standard submit form

    And i have tried making this code but I failed to do so and This is the code created by


    HTML
    Code:
    <form action="page.php" method="post" onsubmit="return login()">
                User Name 
                <input type="text" name="user" id="user" />
                <br/>Password
                <input type="password" name="pass" id="pass" />
                <br/><br/>
                <input type="submit" name="login" id="login" value="Login" onclick="" />
            </form>
            <br /><br />
            <div id="result"></div>
    JavaScript / Ajax
    Code:
    function login(){
        var user = document.getElementById('user').value;
        var pass = document.getElementById('pass').value;
        
        Http.onreadystatechange = function(){
            if (Http.readyState == 4) {
                document.getElementById('result').innerHTML = Http.responseText;
            }
            else {
                document.getElementById('result').innerHTML = "Loading";
            }
        }
        url = "user=" + user + "&pass=" + pass;
        Http.open("post", "page.php", true);
        Http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        Http.send(url);
    }
    PHP
    PHP Code:
    $user $_POST['user'];
    $pass $_POST['pass'];


    if(
    $user == "ahmed" && $pass == "123"){
        echo 
    "Right";
    }
    else{
        echo 
    "Wrong";



    Please Help Me

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    And what is not working?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You are not returning false in your function to cancel the form submit

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You Mr A1ien51

    Is it possible to amend the code above to make what I want


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •