We help IT Professionals succeed at work.

change focus to another input .. not sibling input

Mark Bran
Mark Bran asked
on
44 Views
Last Modified: 2020-04-17
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
Comment
Watch Question

zc2
CERTIFIED EXPERT

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

Open in new window

Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
@Leakim91 - your code blocks any editing of zipcode.
Also "input" handles paste
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
@zc2 - I can paste more than 5 chars into your field. You may want to crop the value or give an error
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

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

Also "input" handles paste
you right, let's remove it
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
(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
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
thank you @Michel
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Did you just edit my comment? Interesting

I would never do that. Which one ? It should be marked as "edited" I think.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
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 
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

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


leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
@Michel Plungjan

JFYI, I reported both comments.
Mark BranFront End Developer

Author

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.