PDA

View Full Version : focus on text field w/o body using AJAX



aug_9
08-08-2007, 03:42 PM
****focus on text field when page loads using AJAX****

Hello all,

In our application we are using AJAX for our home page and all the related pages are included to it.

Its working fine. But i am unable to do focus on the first text field in the included pages as we do for normal form using onLoad & document.formname.elementname.focus funtion in body tag.

Here thre problem is- since it is included pages, we dont have body or form to set focus using above mentioned js function.

Is there any solution for this?
Could any one please tell me the solution for this problem as it is very important.

Thanks in advance,
Aug_09

shachi
08-09-2007, 09:25 AM
Please post a link to the page on your site that contains the problematic script so we can check it out.

jscheuer1
08-09-2007, 03:41 PM
This requires a small transparent .gif image, or really any small image, as it will never be seen. Example code for a page with a form to be loaded via Ajax w/ it's first text field brought to focus:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<form action="#" name="test">
<input type="text" name="text1"><br>
<input type="text" name="text2"><br>
<input type="submit" value="Go">
</form>
<img style="visibility:hidden;position:absolute;top:-1000px;" src="spacer.gif"
onload="setTimeout(function(){document.forms['test']['text1'].focus();},300);">
</body>
</html>