how to use .length with "input"

Black Sulfur
Black Sulfur used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Elvio Lujan.Net Senior Developer

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

Distinguished Expert 2017
Commented:
Using event.target:
$(document).ready(function(){
		$("input").keyup(function(e){            
			if(e.target.value.length >3){
				$(".loader").show();
              e.preventDefault();
              
				}
			});
		});

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial