Hi Guys

i have a formValidation Java Script on the form to validate username and password
text boxes to check whether they are empty,and i am calling them on the Onclient Click
even ton the button, But even If i enter some data into those text boxes the error message
alert appears, what it the problem with my code here ?

`<script type="text/javascript">

function FormValidator() 
{
    if (document.getElementById('txtusername').value == "");
    {

        alert('Invalid User Name');

    }


     if (document.getElementById('txtpassword').value == "");
     {

        alert('Invalid Password');

    }


}

</script>
`

thanks
regards
sumith

Recommended Answers

All 5 Replies

This post is very informative and give the good information.
Click Here

how we can a field validate from database? like when i enter in user abc it validat from database whether valid or not?

In HTML5 you can use attribute "required" to <input type="text" required="required" /> and <input type="password" required="required" /> instead of your js function

i thin u not pick my point. i want to validate a field whether a valid user mean when i enter in user fied abc whether this abc is in the database table or not if yes then ok othere wise it give alert.....

var txtusername = document.getElementById('txtusername').value;
$.post('index.php',{isitinDB:txtusername},
    function(data){return data;});

and index.php

<?
if(isset($_POST['isitinDB'])){
    /* check in db $_POST['isitinDB'] and return true or false */
    exit();
    }

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.