Saturday, March 23, 2013

How to check whether a TextBox has value or not using JavaScript

Using JavaScript we can perform client side validation. It will improve the performance of your web application. Here i have shown a simple basic validation, how to check whether a text box has value or not.
  1. var username=document.getElementById("uname").value;
  2. if (username==null || username=="")
  3. {
  4. alert("Please Enter Username");
  5. document.getElementById("uname").focus();
  6. }

Here the alert is used to display a message box with the text it has. And the focus() is used to move the cursor to the corresponding text box.

No comments:

Post a Comment