#26 Form Validations in JavaScript


Original source


45 responses to “#26 Form Validations in JavaScript”

  1. in some case u r using var = in funtions, and some cases u r direct getting to getelementbyid, no var is attached how to understand where to go ahead with var copy by vaLUE nd copy by referece part its confusing

  2. I copied all of your code into visualstudio code, with index.html and message. The javascript alert works fine, if nothing is entered and press submit, but if I enter a username and password and press submit, it doesn't go to message, I'm on windows 10.

  3. <html>

    <head>

    <title>Form validation</title>

    </head>

    <body>

    <form onsubmit="return getvalidate()" >

    <input id="name" placeholder="Enter name"/><br/>

    <input id="pass" placeholder="Enter password"/><br/>

    <button type="submit">Submit</button>

    </form>

    </body>

    <script type="text/javascript">

    function getvalidate(){

    name=document.getElementById("name").value;

    pass=documetn.getElementById("pass").value;

    if(name==""){

    alert('Fill the name');

    name.style.border="1px solid red;"

    return false;

    }

    else if(pass==""){

    alert('Fill the password');

    pass.style.border="1px solid red";

    return false;

    }

    else{

    return true;

    }

    }

    </script>

    </html>

Leave a Reply