• All
  • Free Web Hosting
  • Category 2
gravatar

How to Validate textbox with Javascript?

This script checks if the text box has value or none. The text box that you are going to validate must be inside the form.

<script language="javascript" type="text/javascript">
<!-- hide script from older browsers
function validateForm(MyForm){

    if ("Username"==document.forms.MyForm.UserName.value){
    alert("Username is Required!");
    document.getElementById('UserName').style.color = '#FF0000';
    document.getElementById('UserName').focus();
    return false;
    }
}
</script>