We help IT Professionals succeed at work.

how to use .length with "input"

Black Sulfur
Black Sulfur asked
on
134 Views
Last Modified: 2017-03-08
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?
Comment
Watch Question

Elvio Lujan.Net Senior Developer
CERTIFIED EXPERT

Commented:
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

CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions