Link to home
Start Free TrialLog in
Avatar of Mark Bran
Mark Bran

asked on

change focus to another input .. not sibling input

Need to change focus from #zipCode input to #feelings input when #zipCode.maxLength === 5
assuming ofcourse #zipCode is not zero based if it is then maxLength 4
They are not siblings

not sure how to set an addventlistener for this assuming that is how I would go about it
Avatar of zc2
zc2
Flag of United States of America image

I would do something like this:
$(function() {
	$("#zipCode").on('input', function(ev) {
  	if(this.value.length >= 5 )
    	$("#feeling").focus();
  } );
})

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe 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
@Leakim91 - your code blocks any editing of zipcode.
Also "input" handles paste
@zc2 - I can paste more than 5 chars into your field. You may want to crop the value or give an error
your code blocks any editing of zipcode.
I was able to edit

Also "input" handles paste
you right, let's remove it
(In Chrome,) when I fill out the zip, I cannot edit it again because your click handler will move the focus because the field is full

Oh, I see, the jsfiddle do not have the click handler
thank you @Michel
Did you just edit my comment? Interesting

I would never do that. Which one ? It should be marked as "edited" I think.
I wrote

(In Chrome,) when I fill out the zip, I cannot edit it again because your click handler will move the focus because the field is full

and then I saw later it was converted to

----
(In Chrome,) when I fill out the zip, I cannot edit it again because your click handler will move the focus because the field is full

Oh, I see, the jsfiddle do not have the click handler
----

which is not what I wrote and I would have written

Oh, I see, the jsfiddle does not have the click handler 
Now it look like two from my last three comments is your.... the site is bugged?


@Michel Plungjan

JFYI, I reported both comments.
Avatar of Mark Bran
Mark Bran

ASKER

Just a follow up because of the additional comments ..... I am running the code input seems to be handling the paste issue
I pasted 9 numbers in it but it corrected it to 5 numbers then focus changed as I wanted it to the next input area
All is working well, with no issues so thanx again for the help it is much appreciated