jquery - Not sure why my div is not showing validation messages -


ello stack, cant seem figure out why there isn't text showing in div after validation of field. here code. know validation running but, i'm not sure why validation message isn't showing in div.

<html> <head>     <script src="scripts/jquery-1.5.2.js" type="text/javascript"></script>     <script src="http://localhost:62147/scripts/jquery.validate.js" type="text/javascript"></script>     <script type="text/javascript">         "use strict";         $(document).ready(function () {              $("#testerbtn").bind("click", function () {                 alert("onclick fired");                 $("#myform").validate({                     errorlabelcontainer: $("#errors"),                     rules: {                         texttoval: { required: true }                     },                     messages: {                         texttoval: "the field required! nub~!"                     }                 });                 alert("validation should have happend.");              })         });      </script>     <title>test page</title> </head> <body>     <form id = "myform" action="htmlpage1.htm">          <div id="errors"></div>         <div>             <input type="text" id="texttoval"  value="" />             <input type="button" id="testerbtn"  value="tester" />         </div>     </form> </body> </html> 

there couple of things see here causing issues:

  1. ensure inputs have name attributes:

    <input type="text" id="texttoval"  value="" name="texttoval" /> 
  2. validate() should instantiated outside of click handler. additionally, change button type submit automatically trigger validation code.

in summary:

javascript:

$(document).ready(function () {     $("#myform").validate({         errorlabelcontainer: $("#errors"),         rules: {             texttoval: {                 required: true             }         },         messages: {             texttoval: "the field required! nub~!"         }     }); }); 

html:

<form id = "myform" action="htmlpage1.htm">               <div id="errors"></div>              <div>                      <input type="text" id="texttoval"  value="" name="texttoval" />                      <input type="submit" id="testerbtn"  value="tester" />              </div>      </form> 

working example: http://jsfiddle.net/fj8xf/


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -