www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 09-27-2005, 04:31 PM
    mitt mitt is offline
    Registered User
     
    Join Date: Dec 2003
    Posts: 9
    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?
    Reply With Quote
      #2  
    Old 09-27-2005, 05:05 PM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,804
    All the bugs are in Internet Explorer my friend
    Quote:
    Originally Posted by drhowarddrfine's signature
    Do you have some code for me to mark up?
    __________________
    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
    Reply With Quote
      #3  
    Old 09-27-2005, 08:20 PM
    tabzter's Avatar
    tabzter tabzter is offline
    Ignorance is bliss!
     
    Join Date: Aug 2005
    Location: The Hill Ch' Hill
    Posts: 381
    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]
    Reply With Quote
      #4  
    Old 09-27-2005, 11:57 PM
    mitt mitt is offline
    Registered User
     
    Join Date: Dec 2003
    Posts: 9
    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);">
    contents of the js/functions.js file
    Code:
    function checkValue(score,fieldname)
    {
      if(score > 10)
      {
          alert("Error!" You have entered an invalid score");
          fieldname.focus();
          fieldname.select();
      }
    }
    What I am looking to do is not let the person entering in these scores move on to the next score box (about 74 more to tab through) unless the value is less than 10. I want to correct it before moving on to the submit because the page scrolls forever in length and I don't want them to be forced to scroll all the way to the top because the first box is wrong.
    Reply With Quote
      #5  
    Old 09-28-2005, 01:24 AM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,804
    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.
    Reply With Quote
      #6  
    Old 09-28-2005, 01:12 PM
    mitt mitt is offline
    Registered User
     
    Join Date: Dec 2003
    Posts: 9
    Still doesn't work. After the alert it just sends the focus to the next input box.
    Reply With Quote
      #7  
    Old 09-28-2005, 05:08 PM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,804
    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.
    Reply With Quote
      #8  
    Old 09-28-2005, 07:37 PM
    mitt mitt is offline
    Registered User
     
    Join Date: Dec 2003
    Posts: 9
    Well it works but I get an error in the JS console after it focuses.


    Quote:
    Error: [Exception... "'Permission denied to get property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: http://www.mydomain.com/js/functions.js :: anonymous :: line 21" data: no]
    Source File: http://www.mydomain.com/js/functions.js
    Line: 21 <- This changes each time
    Reply With Quote
      #9  
    Old 09-28-2005, 08:23 PM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,804
    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>
    Firefox seems to take a little time to set focus back to the page after the alert and needs a split second to do so. I also had to declare my varaible gloabally to work with the setTimeout and for extra security I also added a boolean check onblur.
    __________________
    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.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 09:29 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.