Gary Croxford
asked on
Javascript setfocus() function not consistent
I have a php page and am trying to set the focus to a specific text input box when the page opens using this mechanism:
my problem is that the focus event only fires intermittently - the ProdnOrder input is disabled but the focus is on the path in the address box which is highlighted. but occasionally the focus event works as it should.
How can I force the focus onto the VECode input box everytime?
<script type="text/javascript" language="JavaScript">
function jsSetFocus(){
document.forms["OrderDetail"]["ProdnOrder"].disabled = true;
document.forms["OrderDetail"]["VECode"].focus();
}
jsSetFocus();
my problem is that the focus event only fires intermittently - the ProdnOrder input is disabled but the focus is on the path in the address box which is highlighted. but occasionally the focus event works as it should.
How can I force the focus onto the VECode input box everytime?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>Julian Hansen
Works a treat, thank you.
I had tried disabled and autofocus attributes for the relevant elements but they aren't working, don't know why. Would the fact that I'm writing the html as echo commands - echo '<input type="text" ... etc have any impact? Can't think why it would.
Works a treat, thank you.
I had tried disabled and autofocus attributes for the relevant elements but they aren't working, don't know why. Would the fact that I'm writing the html as echo commands - echo '<input type="text" ... etc have any impact? Can't think why it would.
No it should not have an impact that the code is being generated dynamically.
Do you have a sample of the rendered output that is not working (where disabled and autofocus are defined as part of the element)?
Do you have a sample of the rendered output that is not working (where disabled and autofocus are defined as part of the element)?
Open in new window