Can't get jquery form input validation working -


noob question...

had same kind of question yesterday. managed working without answer. today, same script, different divs -not working.

html of it

<div class="imgform"> <form> login: <input type="text" id="imglogin" name="login"> password: <input type="password" id="imgpass" name="pass">  <a class="imglogin" href="#">login</a> </form> </div> 

and script self

$(".imglogin").click(function(){      var password = "111";     if($("#imgpass").val() !== password) {         $("#imgform").text("incorrect password");     } else {         window.location.href = "http://google.com";    

} });

went on script few times. can't figure out mistake

you must load jquery in <head> block

<script src="//code.jquery.com/jquery-1.9.1.js" type="text/javascript"> 

html (added div id of imgform display answers)

<div class="imgform">     <form>login:         <input type="text" id="imglogin" name="login">password:         <input type="password" id="imgpass" name="pass"> <a class="imglogin" href="#">login</a>             <div id="imgform"></div>     </form> </div> 

try this

$(window).load(function(){ $(".imglogin").click(function () { console.log('working')     var password = "111";     if ($("#imgpass").val() != password) {         $("#imgform").text("incorrect password"); //i added div id imgform     } else {         window.location.href = "http://google.com";     } }); }); 

demo


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -