Knowledge Walls

Ad Size: (333 X 90) px
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Input:text in Form Validation of JQuery
490 Views
HTML
<table border="0" cellpadding="3" cellspacing="0">
   <tr>
      <td valign="top" style="padding-top: 6px;">Name</td>
      <td>
          <input type="text" id="txt_name" />
          <div class="error" id="txt_name_error"></div>
      </td>
    </tr>
    <tr>
      <td colspan="2" align="right">
          <button id="txt_submit">Okay</button>
      </td>
   </tr>
</table>
CSS
.error {
   color: red;
}
JQuery
$(document).ready(function(){
   $("#txt_name").keypress(function(event){
      if (event.which == 13) {
         $("#txt_submit").trigger("click");
      }
   });
   $("#txt_submit").click(function(){
      if ($("#txt_name").val() == ""){
        $("#txt_name_error").html("Name is required!");
        $("#txt_name").focus();
      }
      else {
        $("#txt_name_error").html("");
        alert("okay");
      }
   });
});
Demo & Output 
Next Topics
Next lessons of current book.
HTML Insertion of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
Previous Topics
Previous lessons of current book.
Event handler methods of JQuery
Jquery Exercises of JQuery
Best Lessons of "JQuery"
Top lessons which are viewed more times.
Form Validation of JQuery
HTML Insertion of JQuery
Jquery Exercises of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
Event handler methods of JQuery
HTML Form of JQuery
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details