Jump to content

Recommended Posts

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;
		}
	}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/275201-why-keyup-is-not-working/
Share on other sites

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 by teynon

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;
		}
	}

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;
		}
	}
});

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 by teynon
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.