Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:12:44+00:00 2026-05-29T12:12:44+00:00

In Firefox this section of the code never seems to return true. Yet it

  • 0

In Firefox this section of the code never seems to return true. Yet it works perfectly well in Google Chrome

if(restrictCharacters(this, event, digitsOnly)==true)

What should be happening is that if the user inputs a number from 1 to 5 in the input box with the ID E1Rating the function returns true and runs the code nested underneath. But in Firefox nothing happens after a participant enters the number.

I stripped the code down to the part that’s not working in Firefox. So you can see how it’s being used.

document.getElementById("E1TimeStart").value = startTime;       
$('#E1Rating').keyup(function() {
    if(restrictCharacters(this, event, digitsOnly)==true){                  
        clearTimeout(mytimeout);                                                                        
        var rateTime = new Date().getTime();                
        $('#E1Rate').hide();                                                
        document.getElementById("E1TimeEnd").value = rateTime;              
        PrepareBox2();                                                      
    }
    else{
        //Do nothing and wait for the timeout
    }
});

};

This is the restrictCharacters function. I know it works since again it works in Chrome. Also the function works in Firefox if you use it outside of the if == true function. My suspicion from searching and trying things is that it might be the event reference in the (this, event, digitsOnly). But if that’s the case what is it specifically?

/* Purpose: Code will restrict false until it detects the numbers 1 through 5 */
/* Code Source: originally from qodo.co.uk */
// create as many regular expressions here as you need:
var digitsOnly = /[1-5]/g;

function restrictCharacters(myfield, e, restrictionType) {
    if (!e) var e = window.event
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);

    // if they pressed esc... remove focus from field...
    if (code==27) { this.blur(); return false; }

    // ignore if they are press other keys
    // strange because code: 39 is the down key AND ' key...
    // and DEL also equals .
    if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40) {
        if (character.match(restrictionType)) {
            return true;
        } else {
            return false;
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:12:45+00:00Added an answer on May 29, 2026 at 12:12 pm

    You have to define event as a function parameter. Google Chrome and IE support the non-standard global event property, which refers to the latest event object.

    $('#E1Rating').keyup(function(event) { //<--
        if(restrictCharacters(this, event, digitsOnly)){
    

    Note: if (.. == true) can safely be replaced with if (...), because any expression which is equal to true, is also true as an assertion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works perfectly in Firefox but doesnt work in ie i get the following
I have this piece of code which works in Firefox link = $('<a>link</a>'); var
This .show and .hide works great in Firefox 3 but not in IE 7.
I have this section of code: function createDownload() { var category, format, specification, download;
This javascript code run without problem in chrome and IE but have a problem
I've converted a Flash SWF file to HTML5 using Google Swiffy. This works fine
Firefox recently blacklisted the plugin that allows xbaps to work in firefox This is
Firefox has this nice find-a-text-on-the-page dialog, which is non-modal and shows up at the
<?php $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; echo $language; ?> When I use Firefox to test this
Is this doable in either IE7 or Firefox?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.