Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Input:text in Form Validation of JQuery
2916 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
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
Best Lessons of "JQuery"
Top lessons which are viewed more times.
HTML Insertion of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
HTML Insertion of JQuery
Form Validation of JQuery
HTML Form of JQuery
HTML Insertion of JQuery
HTML Insertion 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