Forum Moderators: open

Message Too Old, No Replies

Firebox onfous and alert problem

Firebox onfous and alert problem

         

manny

2:01 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Hi all,
I have been facing a problem with Firefox 1.0.1 on lynix! I have a text box and I have to show some message (in the form of Javascript alert) to user whenever user sets focus to that text box.

Textbox's onfocus event is set as follows where Show Prompt displays the actual alert box:
onfocus="ShowPrompt();"

ShowPrompt has nothing but a simple alert statement in it ==>> alert("hello world");

Code runs as expected in IE but behaves abnormally in Firefox! In Firefox, it keep popping up the alert box as if I am calling the ShowPrompt method in a loop! this does not occur on IE and IE displays the alert box only once!

What I might be doing wrong here? or how to make Firefox alert a message only once? any insights?

Thanks,
Manny

BlobFisk

2:09 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of onfocus try using onblur:

onblue="ShowPrompt();"

Or else put a button beside the text input and use onClick

HTH

manny

2:17 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



correct me if I am wrong but the onblur event is fired when the control looses the focus. am I right? the application requirement is to show the alert box as soon as the focus moves to the control!

Is there anyother way around this problem? did you also face any problem like that one?

Thanks,
Manny

BlobFisk

2:27 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apologies - I didn't read your message correctly!

Interesting one - you could use onClick but that will not account for tabbed movement of the focus...

Oh, and welcome to WebmasterWorld manny!

manny

2:31 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



thanks!

I know onclick is the last option for me but that would not address the tabbed navigation!

Is that a known problem with Firefox?

guys, i really need any other work around :( SOS!

ajkimoto

4:21 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Hi manny,

It almost sounds like the browser is treating the popup as an object so that when you dismiss the popup, it resets focus to the textbox, refiring the function etc.,

What about something like this?

<script type="text/javascript">
<!--
//global var to hold ref to last object blurred
var lastObj=''

//sets lastObj to the object that was blurred
function setLastObj(obj){
lastObj=obj
}

//checks to see if current object is the same as
//the last blurred object--if so, no popup
function showAlert(obj){
if (obj!=lastObj){
alert('Hello World!')
}
}
//-->
</script>

<style type="text/css">

</style>

</head>

<body>
<input id="txtA" onfocus="showAlert(this)" onblur="setLastObj(this)" />

I don't have linux so can't prove that this will work, but it might be worth a shot...

ajkimoto