Marko
Marko

Reputation: 213

focus() isn't working on second call

I have two input fields, with their respective ids, and save button.

When save button (ajax) is clicked, data get saved but page stays.

So, I want to return focus to input field. I get what input field was in focus with jquery blur() and put it into focuswhat variable. Then, after data get saved with jquery post(), I call line:

document.getElementById(focuswhat).focus();

It works first time.

But, when data get saved again, focus doesn't work. Any ideas why?

EDIT: disregard this question, I made obvious oversight in code, everything is working fine. Good tip for getElementById btw.

Upvotes: 2

Views: 789

Answers (1)

Jatin Dhoot
Jatin Dhoot

Reputation: 4364

You should write this code in $.ajax's success block.

BTW if you are using jquery $(focuswhat).focus() will do.

You need not write this big getlemenetById syntax,

Here i am assuming focuswhat variable contains the value of id.

Upvotes: 1

Related Questions