|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
focus() Firefox & IE
I am trying to create a validation script that works in both Firefox and IE. I would like to set the focus back to the field with the error but can't seem to get it to work. I have made it work in IE but in Firefox I get the alert as I should but then the focus moves to the next field in the tab order. Is there a way to fix this? Is this a bug in Firefox?
|
|
#2
|
||||
|
||||
|
All the bugs are in Internet Explorer my friend
Quote:
__________________
Ultimater XMLHttpRequest: Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo Broadening one's horizons: 24ways.org Note I have a bad habit of editing my posts hours at a time and hours later. Last edited by Ultimater; 09-27-2005 at 05:08 PM. Reason: added a link |
|
#3
|
||||
|
||||
|
Internet Explorer - Bad Bad Bad
Mozilla FireFox - Good Good Good huga buga huga chuga...
__________________
When you have eliminated the impossible, whatever remains, however improbable, must be the truth ! [Sir Arthur Conan Doyle] |
|
#4
|
|||
|
|||
|
The whole script is pretty large but this is a scaled down version
Code:
<script language='JavaScript1.2' type='text/javascript' src='js/functions.js'></script> <input type="hidden" value="" name="match_1_player_1_game_1" onblur="checkValue(this.value,this.name);"> Code:
function checkValue(score,fieldname)
{
if(score > 10)
{
alert("Error!" You have entered an invalid score");
fieldname.focus();
fieldname.select();
}
}
|
|
#5
|
||||
|
||||
|
Code:
<script type="text/javascript">
function checkValue(score,fieldname)
{
if(score > 10 || isNaN(score))
{
alert("Error! You have entered an invalid score");
fieldname.focus();
fieldname.select();
}
}
</script>
<input type="text" value="" name="match_1_player_1_game_1" onblur="checkValue(this.value,this);">
__________________
Ultimater XMLHttpRequest: Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo Broadening one's horizons: 24ways.org Note I have a bad habit of editing my posts hours at a time and hours later. Last edited by Ultimater; 09-28-2005 at 01:26 AM. |
|
#6
|
|||
|
|||
|
Still doesn't work. After the alert it just sends the focus to the next input box.
|
|
#7
|
||||
|
||||
|
Oh, I see what you mean now, I didn't add a blank INPUT field after your example. All you need to do is add a timeout:
Code:
if(score > 10 || isNaN(score))
{
alert("Error! You have entered an invalid score");
setTimeout(function(){fieldname.focus();fieldname.select();},10)
}
__________________
Ultimater XMLHttpRequest: Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo Broadening one's horizons: 24ways.org Note I have a bad habit of editing my posts hours at a time and hours later. |
|
#8
|
|||
|
|||
|
Well it works but I get an error in the JS console after it focuses.
Quote:
|
|
#9
|
||||
|
||||
|
This might be a little over board but it works none-the-less:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Image Viewer</title>
<script type='text/javascript'><!--
var checkFocus=true;checkEl=null;
function checkValue(score,fieldname)
{
checkFocus=false;
if(score > 10 || isNaN(score))
{
checkEl=fieldname;
alert("Error! You have entered an invalid score");
setTimeout(function(){if(checkEl)checkEl.focus();checkEl.select();},100);
}
checkFocus=true;
}
//--></script>
</head>
<body>
<p>
<input type="text" value="" name="match_1_player_1_game_1" onblur="if(checkFocus){checkValue(this.value,this)}">
<input type="text" value="">
</body>
</html>
__________________
Ultimater XMLHttpRequest: Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo Broadening one's horizons: 24ways.org Note I have a bad habit of editing my posts hours at a time and hours later. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|