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?
LVL 1
Black SulfurAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Elvio Lujan.Net Senior DeveloperCommented:
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

0
Leonidas DosasCommented:
Using event.target:
$(document).ready(function(){
		$("input").keyup(function(e){            
			if(e.target.value.length >3){
				$(".loader").show();
              e.preventDefault();
              
				}
			});
		});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.