a65 Posted March 4, 2013 Share Posted March 4, 2013 Blur is working properly in codeignitor but why not keyup? var form = $("#myform"); var cname = $("#company_name"); var cnameInfo = $("#cnameInfo"); cname.blur(validateName); cname.keyup(validateName); function validateName(){ if(cname.val().length < 4){ cname.addClass("error"); cnameInfo.text("We want names with more than 3 letters!"); cnameInfo.addClass("error"); return false; } else{ cname.removeClass("error"); cnameInfo.text(""); cnameInfo.removeClass("error"); return true; } } Quote Link to comment https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/ Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 (edited) I don't use codeignitor, but I don't think it has much to do with your jquery / javascript code? When you use those event handlers, I recommend using "on". cname.on("blur", function() { validateName(); }); cname.on("keyup", function() { validateName(); }); Edited March 5, 2013 by teynon Quote Link to comment https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/#findComment-1416618 Share on other sites More sharing options...
a65 Posted March 5, 2013 Author Share Posted March 5, 2013 this function is not doing any change even using it blur is also not working Quote Link to comment https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/#findComment-1416667 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 If you use the .on like I was suggesting, you'll need to change the function as well. var form = $("#myform"); var cname = $("#company_name"); var cnameInfo = $("#cnameInfo"); cname.on("blur", function() { validateName(this); }); cname.on("keyup", function() { validateName(this); }); function validateName(cname){ if(cname.val().length < 4){ cname.addClass("error"); cnameInfo.text("We want names with more than 3 letters!"); cnameInfo.addClass("error"); return false; } else{ cname.removeClass("error"); cnameInfo.text(""); cnameInfo.removeClass("error"); return true; } } Quote Link to comment https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/#findComment-1416668 Share on other sites More sharing options...
a65 Posted March 5, 2013 Author Share Posted March 5, 2013 still is not working plz have a look at my whole code as u suggested $(document).ready(function(){ //global vars var form = $("#myform"); var cname = $("#company_name"); var cnameInfo = $("#cnameInfo"); cname.on("blur", function() { validateName(this); }); cname.on("keyup", function() { validateName(this); }); function validateName(cname){ if(cname.val().length < 4){ cname.addClass("error"); cnameInfo.text("We want names with more than 3 letters!"); cnameInfo.addClass("error"); return false; } else{ cname.removeClass("error"); cnameInfo.text(""); cnameInfo.removeClass("error"); return true; } } }); Quote Link to comment https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/#findComment-1416670 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 (edited) Have you tried anything else with the code I sent you? Just because I provided you with code doesn't mean that code will plug and play. I wrote it to get you started. http://jsfiddle.net/CZxbM/ $(document).ready(function(){ var cname = $("#imabox"); cname.on("blur", function() { validateName($(this)); }); cname.on("keyup", function() { validateName($(this)); }); }); You need to look into learning how to debug javascript with Firefox or Chrome. Edited March 5, 2013 by teynon Quote Link to comment https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/#findComment-1416837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.