Reputation: 2031
In my page I have a html form which saves data using jquery/ajax. I am calling jquery/ajax when the users mouse leaves the input field. So for example I have the following fields:
1. name : <input type="text" name="name" id="name">
2. email : <input type="text" name="email" id="email">
3. mobile : <input type="text" name="mobile" id="mobile">
So when the users mouse leaves any of the fields, jquery/ajax is used to store the data in the database.
Now my questions is: When I am typing in the 'name'-field and then I immediately switch to the second field, the 'email'-field using keyboard tab. After that it's loading the page because I am calling it when the mouse leaves from a field. Now I want to focus on the second field when the page is loaded. Not only for the second field, it should work for any field. How to achieve this?
Upvotes: 0
Views: 1453
Reputation: 4320
Why are loading page again if you are doing ajax call? Just load the section which you want to really update after ajax save. If you want to show another section as per open/action value selection you can do that without page loading.
If that section is already available in DOM with hide
mode then after success ajax call just make that show
. But if the section is not really exist in the DOM then after ajax call just generate the HTML content for that section on the fly and then put it in your DOM where you need it.
That's all. Ajax call are basically used to not reload the page. If you are loading the page then ajax call is not require at all you can just do that in normal post
way.
Hope this will helps you!
Upvotes: 1
Reputation: 1422
in success part of your ajax call you can point to next input like:
$("#email).focus();
Upvotes: 1