473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

hard to repeat javascript error

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 ?


Nov 19 '05 #1
4 1052
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
"Maverick" wrote:
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 ?

Nov 19 '05 #2
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.
"Maverick" <Ma******@discussions.microsoft.com> wrote in message news:23**********************************@microsof t.com...
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 ?


Nov 19 '05 #3
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

"DotNetJerome" wrote:
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
"Maverick" wrote:
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 ?

Nov 19 '05 #4
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 ?

"George" wrote:
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.
"Maverick" <Ma******@discussions.microsoft.com> wrote in message news:23**********************************@microsof t.com...
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 ?

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sentinel | last post by:
Hi all, I'm trying to reload a frame from a pop-up, but really cannot figure this out. Within my index.htm file, I make a link to call a pop-up frame with a javascript function that calls the...
6
by: milkyway | last post by:
Hello everyone, What is the correct way to incorporate a .js file into an HTML file *IF* the .js file on a hard disk? What I have tried is listed below but it does not work... When trying to...
2
by: debugger | last post by:
background-repeat: repeat-x works fine in IE and FF and as expected, produces something like ............ hello ............ On Safari, the output is not what is desired....
14
by: Roland Hall | last post by:
Since I'm not getting any response from the community, I'm reposting this under my managed account. I've turned my web.config friendly error messages off and it may be easier to view what I'm...
4
by: tsiGeorge | last post by:
When the web page takes a while to process users get impatient and click the button again. I need to throw these extra clicks away or disable the button after the first click. -- tsiGeorge
8
by: Csaba Gabor | last post by:
I wrote a .repeat(n) function for strings which seemed to work fine: String.prototype.repeat = function(n) { // repeats the string n times if (n<1) return ""; if (n<2) return this; for (var...
3
by: Jana | last post by:
Good morning, Access gurus! I'm having a brain fart and can't seem to wrap my head around the logic for this problem, so I'm hoping someone out there can help me out. Here's my situation: I...
7
by: Jon Slaughter | last post by:
Can someone point me to some resources on how to tile an image to create a border? <td> <img src="images/MTile.png" width="1" height="30" alt=""></td> I have something like that where I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.