addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgoogleimageimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

JaxPHP / JaxWeb Message Board › Set focus to form field inside an AJAX-delivered DIV

Set focus to form field inside an AJAX-delivered DIV

A former member
Post #: 53
I guess all this is elementary to most here but what would be the best way to set focus on a form after AJAX does its thing? Guess easy but I was not able to find a good answer out there on the search engines.

Anyone have a good suggestion to set the focus to a text input field "input1" received from an AJAX call. Not all my AJAX calls return an input1. Fun thing about programming is learning how others do things, as there are so many ways to do things.

Tim
ZipOnOver
A former member
Post #: 54
Okay, how about this?

In the primary js file with the AJAX functions after the:
document.getElementById(dvnmbr).in­nerHTML = response;
}


Add this:
if (document.getElementById && (inptt =
document.getElementById('input1'))) {
document.getElementById('input1').focu­s();
}


This way the AJAX is done and the JavaScript can set the focus without being concerned with if the element exists. Most examples tried to send it with the call or use a time delay to hopefully perform the function after the field has been created.

I was just wondering if someone had a better way,

Tim
Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy