Get focus after an alert pop-up

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 :slight_smile:

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>

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.

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.

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");

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 :slight_smile: