hard to repeat javascript error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a javascript function that using to set focus to a text box after
clicking a button (butSearch) which is called in Page_Load
**********************************************
dim jsscript as string
jsscript = jsscript + " document.getElementById('txt_S_ItemCode').focus(); "
jsscript = jsscript + " { alert('Please input item barcode.'); return
false; }"

butSearch.Attributes.Add("onclick", jsscript)
**********************************************
The function worked. However, once in awhile the function failed to focus on
back to the textbox. I think there's around 1 time per every 10 trails. Do
you guys have any idea about how to fix it ?
 
Hi,

What I'm guessing is...The text box receives the focus, since you are
displaying the alert, after responding to alert mesg.... the focus is not
going to the Text box.

So rewrite your function, in this way...first you display the alert message
then try to put the focus in the text box.

jsscript = jsscript + " { alert('Please input item barcode.');
jsscript = jsscript + " document.getElementById('txt_S_ItemCode').focus();


Cheers,

Jerome. M
 
The IE displays page as it becomes available.
The same with JavaScript. It executes when page might not be loaded fully.
So if you are trying to set focus (actually use getElementById) before the input control was rendered then you get an error.

Check if you have situation like this.


George.


I have a javascript function that using to set focus to a text box after
clicking a button (butSearch) which is called in Page_Load
**********************************************
dim jsscript as string
jsscript = jsscript + " document.getElementById('txt_S_ItemCode').focus(); "
jsscript = jsscript + " { alert('Please input item barcode.'); return
false; }"

butSearch.Attributes.Add("onclick", jsscript)
**********************************************
The function worked. However, once in awhile the function failed to focus on
back to the textbox. I think there's around 1 time per every 10 trails. Do
you guys have any idea about how to fix it ?
 
ur suggestion is exactly the first version of my code ....
the situation is even worser ...
the focus is not set by 3-4 times per every 10 trial
it's so random that i can't repeat the error ...
i juz can evaluate how often that appear
 
I've thought about that too
I tried to put the focus code in the Page_PreRender event but still doesn't
work perfectly ....
or is there some where else i can choose to implement the auto focus
function ?
 
Back
Top