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
JavaScript

Avatar of undefined
Last Comment
Mark Bran

8/22/2022 - Mon
zc2

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
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Michel Plungjan

@Leakim91 - your code blocks any editing of zipcode.
Also "input" handles paste
Michel Plungjan

@zc2 - I can paste more than 5 chars into your field. You may want to crop the value or give an error
Your help has saved me hundreds of hours of internet surfing.
fblack61
leakim971

your code blocks any editing of zipcode.
I was able to edit

Also "input" handles paste
you right, let's remove it
Michel Plungjan

(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
leakim971

thank you @Michel
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Michel Plungjan

Did you just edit my comment? Interesting

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

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 
leakim971

Now it look like two from my last three comments is your.... the site is bugged?


All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
leakim971

@Michel Plungjan

JFYI, I reported both comments.
ASKER
Mark Bran

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