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

Blurred text
THIS SOLUTION IS 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
@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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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 
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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


Avatar of leakim971
leakim971
Flag of Guadeloupe image

@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
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo