Avatar of Crazy Horse
Crazy Horse
Flag 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?
jQuery

Avatar of undefined
Last Comment
Leonidas Dosas

8/22/2022 - Mon
Elvio Lujan

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
Leonidas Dosas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck