Basic HTML Form validation using JavaScript


Original source


32 responses to “Basic HTML Form validation using JavaScript”

  1. Hello…. thanks for the coding i will love to know… haw can i do this same thing but with more user and the controll of the tipe of user that is doing the loging… can you help me? thanks

  2. <!DOCTYPE html>
    <html lang="un">
    <head>
    <meta charset="utf-8"/>
    <title>Authentication form</title>
    <link rel="stylesheet" href="css/style.css" type="text/css">

    </head>
    <body>
    <form name="loginform" action="index.html" onsubmit="return validateForm()" method="post">
    username:<input type="text" name="username"/><br><br>
    Password:<input type="password" name="passwords"/><br><br>
    <input type="submit"value="submit"/>
    </form>
    <script type="text/javascript">
    function validateForm()
    {
    return true;
    var x=document.form["loginform"]["username"].value;
    var y=document.form["loginform"]["pwd"].value;
    if(x==null||x==" "||y==null||y==" ")
    {
    alert("user name and password must be filled");
    }
    return false;

    }
    </script>

    </body>

    </html>
    I tried the same but i am not getting alert box in function validate form()

  3. I want to take value from two input and add them and display in other input box… my code is not working !! can u fix the code..
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>My javaWebpage</title>
    <meta charset="utf-8"/>
    <script type="text/javascript">
    function myfunction()
    {
    var x=document.["myform"].["number1"].value;
    var y=document.["myform"].["number2"].value;

    var total=x + y;
    document.getElementById("ans1").innerHTML= total;

    }
    </script>
    </head>
    <body>
    <form action="#" method="post" name="myform" onsubmit="myfunction()">
    <input type="number" name="number1" >
    <input type="number" name="number2" > &nbsp; &nbsp;Answer:-<input type="text" id ="ans1" name="answer"><br>
    <input type="submit" name="submitFORM" id="ans1" value="submit">
    </form>
    </body>
    </html>

  4. I am trying to learn javascipt but valudation does not work all it does is says save password or doesnt have a popup

    <html>
    <head>
    <script>
    function submitFunction() {

    var x=document.form["myForm"]["username"].value;
    var y=document.form["myForm"]["password"].value;
    if(x == null || x == "" || y == null || y == "") {
    alert("Both fields can't be empty.");
    } else {
    if(x == "webi") {
    if(y == "12345") {
    alert("Login successful");
    } else {
    alert("Password do not match!");
    }
    } else {
    alert("User doesn't exist");
    }
    }

    }
    </script>
    </head>
    <body>
    <form name="myForm" onsubmit="submitFunction()">
    username: <input type="text" name="username"><p>
    password: <input type="password" name="password"><br>
    <input type="submit" value="submit">
    </form>
    </body>
    </html>

  5. How can make mobile number verification in PHP like gmail or YouTube and more website

    Sir app mobile sms verification tutorial kab bane ge jis me user ke number par code jaye or vo number verification kar sake please sir make this tutorial

  6. can you plz validate a form using events like if a text field  is only for characters and a digit is entered in that field then it shows a message instantly & does not goes to the next field  plz,plz do this

Leave a Reply