Jump to content


Photo

why keyup is not working?

codeignitor

  • Please log in to reply
5 replies to this topic

#1 a65

a65

    Member

  • Members
  • PipPip
  • 25 posts
  • LocationIndia
  • Age:22

Posted 04 March 2013 - 12:04 AM

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

 

 

 



#2 teynon

teynon

    Advanced Member

  • Members
  • PipPipPip
  • 894 posts

Posted 04 March 2013 - 09:05 PM

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, 04 March 2013 - 09:05 PM.

Support my Kickstarter Project!
http://www.kickstart...7618755/antroid

http://www.thomaseynon.com

Vulnerabilities: http://cwe.mitre.org...x.html#Guidance - MySQL.com hacked with SQL Injection - If it happened to them, it can happen to you.


#3 a65

a65

    Member

  • Members
  • PipPip
  • 25 posts
  • LocationIndia
  • Age:22

Posted 04 March 2013 - 11:43 PM

this function  is not doing any change even using it blur is also not working



#4 teynon

teynon

    Advanced Member

  • Members
  • PipPipPip
  • 894 posts

Posted 04 March 2013 - 11:48 PM

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

Support my Kickstarter Project!
http://www.kickstart...7618755/antroid

http://www.thomaseynon.com

Vulnerabilities: http://cwe.mitre.org...x.html#Guidance - MySQL.com hacked with SQL Injection - If it happened to them, it can happen to you.


#5 a65

a65

    Member

  • Members
  • PipPip
  • 25 posts
  • LocationIndia
  • Age:22

Posted 05 March 2013 - 12:02 AM

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


#6 teynon

teynon

    Advanced Member

  • Members
  • PipPipPip
  • 894 posts

Posted 05 March 2013 - 06:30 PM

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, 05 March 2013 - 06:30 PM.

Support my Kickstarter Project!
http://www.kickstart...7618755/antroid

http://www.thomaseynon.com

Vulnerabilities: http://cwe.mitre.org...x.html#Guidance - MySQL.com hacked with SQL Injection - If it happened to them, it can happen to you.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com