Link to home
Start Free TrialLog in
Avatar of Crazy Horse
Crazy HorseFlag for South Africa

asked on

how to use .length with "input"

I have two text fields which are pretty much the same. The only difference is that one has a name of "name" and the other a name of "surname".

I am trying to not use ID's but rather just "input" to trigger a loader when either has text inputted.

$(document).ready(function(){
		$("input").keyup(function(){
			if("input".length >3){
				$(".loader").show();	
				}
			});
		});

Open in new window


The loader should only display after 3 characters are entered. With this code, the loader appears after typing only one character.

Secondly, how can I get the loader to show in the text box that has text being entered into it?
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

Ok, if you are trying to attach the keyup event to your input named "name" and ask if the value is greater than 3, do the following:

$(document).ready(function(){
		$('input[name=name]').keyup(function(){
			if($('input[name=name]').val().length >3){
				$(".loader").show();	
				}
			});
		});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial