View Full Version : Get focus after an alert pop-up
pom
September 1st, 2003, 12:30 PM
Hi guys,
When an illegal character comes up in a textfield, I have an alert pop-up telling me how stupid I am, and I'd like to automatically set the focus to the right textbox, but I don't know how to detect the closing of the pop-up.
Any ideas?
pom :)
λ
September 1st, 2003, 01:35 PM
I'll assume you know how to set the focus to a textfield(because I don't :P). You can use the onunload event of body to run Javascript. Something like this:
<html>
<head>
<title>close me!</title>
<script language="JavaScript">
function traceMe(){
alert('You closed the window! How dare you...');
}
</script>
</head>
<body onunload="traceMe()">
</body>
<html>
Freddythunder
September 1st, 2003, 01:57 PM
I think Pom's talking about from an windows alert box. You know, the ones that only have an okay button - or what some bastards are using as the 'new popup' advertisements.
And, no, I cant think of a way unless you have a script that repeatedly sets focus, but then you could only enter info in one field.
claudio
September 1st, 2003, 01:59 PM
njs12345, i dont think thats what Ilyas want.
I understood he wants to detect the window.alert closing. :-\
Ilyas, i dunno if thats possible, and if not, you could use the window.confirm method.
λ
September 1st, 2003, 02:36 PM
I think script processing is paused while an alert box is up, so you can just go
alert("YOU ARE A FOOL!");
//assuming that setFocus is what you use to set focus
this.setFocus("blahtext");
pom
September 2nd, 2003, 04:57 AM
njs12345 >> Many thanks, I thought I had tried that, but apparently not hard enough, but it works:
function controlForm () {
// ...
if ( ! checkText ('rechercher') ) {
alert ("Invalide characters") ;
GiveFocus("texte") ;
return false ;
}
return true ;
}
function GiveFocus(name) {
document.forms[0].elements[name].focus();
}
Originally posted by claudio
Ilyas, i dunno if thats possible, and if not, you could use the window.confirm method. I'll look in to that too, thanks Claudio :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.