i am using html inputbox , which is inside update panel i need the cursor to be set focused on that inputbox once the page is loaded so i called a function as follows
< body onload="javascript:document.Default.UserInputTextBox.focus();" >
but i getting the following Javascript error,
Microsoft JScript runtime error: 'document.Default.UserInputTextBox' is null or not an object
please help on this
i am using html inputbox , which is inside update panel i need the cursor to be set focused on that inputbox once the page is loaded so i called a function as follows
< body onload="javascript:document.Default.UserInputTextBox.focus();" >
but i getting the following Javascript error,
Microsoft JScript runtime error: 'document.Default.UserInputTextBox' is null or not an object
please help on this
Share Improve this question edited Feb 22, 2010 at 6:18 austin cheney asked Feb 22, 2010 at 6:15 user271628user271628 1013 silver badges15 bronze badges 4-
@svb123 Please show the HTML for the
UserInputTextBox
. – Doug Neiner Commented Feb 22, 2010 at 6:19 - try : < body onload="document.getElementById('UserInputTextBox').focus();" > – jjj Commented Feb 22, 2010 at 6:19
- more code ..more code... whole code.. – jjj Commented Feb 22, 2010 at 6:23
- 1 fast...we have an other questions to answer – jjj Commented Feb 22, 2010 at 6:25
2 Answers
Reset to default 3You've got to wait for the DOM to be ready before trying to access elements in the dom; The onload event listener can wait for the entire document to be loaded including images and css... Which might be undesirable.
<head>
<script type="text/javascript" charset="utf-8">
// wait for the DOCUMENT to bee ready.
window.onload=function(){
walkmydog()
}
</script>
</head>
Here's a detailed explanation for overing this sort of problem: http://www.javascriptkit./dhtmltutors/domready.shtml
A lot of people use javascript frameworks, like jQuery, MooTools, YUI, to overe the browse inpatibility problems.
I do not think it is in the best interest of accessibility to dynamically alter a user's focus prior to alerting the user of such a change. What you can do that is accessible is redirect a user to a fragment URI pointing to the id attribute of the document object in question. That way you are not having to use any JavaScript.
So, for instance, if a user requests a page at this URI:
http://example./page.html
You can redirect the user with your ASP code and a HTTP 302 code to this page:
http://example./page.html#myInputIDValue
That would presume the input field in question had the following attribute:
id="myInputIDValue"
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745388419a4625547.html
评论列表(0条)