JavaScript This piece of javascript code is working in chrome but not in firefox

I have a created a calculator using Jquery and Javascript, everything works fine in Chrome but not in Firefox.

function validate(x, y, z) {
if ((isNaN(x) || x == "") || (isNaN(y) || y == "")) {
return "Please Enter A Valid Number";
} else if (z == "/" && y == 0) {
return "Divide By zero error";
} else if (event.keyCode == 32) {
return false;
} else {
return calculation(x, y, z);
}
}

Demo Here

Answer:1

Do not rely on window.event. It is a Microsoftism that not all browsers implement. However, each handler will receive the event as a parameter. Use it explicitly:

$(document).ready(function() {
  $("#first").focus();
  $('#first,#second,#oper').keyup(function(evt) {
    // HERE                                ^^^
    $('#demo').html(validate(evt.keyCode, $('#first').val(), $('#second').val(), $('#oper').val()));
    // and HERE              ^^^^^^^^^^^
  });
});

function validate(key, x, y, z) {
  // and HERE     ^^^
  if ((isNaN(x) || x == "") || (isNaN(y) || y == "")) {
    return "Please Enter A Valid Number";
  } else if (z == "/" && y == 0) {
    return "Divide By zero error";
  } else if (key == 32) {
    return false;
  } else {
    return calculation(x, y, z);
  }
}
Answer:2

With this HTML the function myFunc() can be executed. https://myurl.de/myjs.js has the function myFunc in it. <head> <script type="text/javascript" src="https://myurl.de/myjs.js"></...

With this HTML the function myFunc() can be executed. https://myurl.de/myjs.js has the function myFunc in it. <head> <script type="text/javascript" src="https://myurl.de/myjs.js"></...

I need to initialize a Vue component's data with the result of an AJAX call. I tried the following: data: function () { return { supplierCount: 0 } }, created: function () { axios.get("/...

I need to initialize a Vue component's data with the result of an AJAX call. I tried the following: data: function () { return { supplierCount: 0 } }, created: function () { axios.get("/...

  1. initialize with data transfer
  2. initialize data from props vue
  3. initialize data in struct
  4. initialize data in java
  5. initialize data in orchestrator
  6. initialization with data
  7. initialization data in c++
  8. initialize dataframe with column names
  9. vue initialize data with function
  10. initialize dataframe with zeros
  11. vue initialize data with computed
  12. data initialization in oops
  13. vue js initialize data with props
  14. initialize arraylist with data
  15. initialize select2 with data
  16. initialize list with data java
  17. initialize list with data c#
  18. initialize dictionary with data c#
  19. datatable initialize with data
  20. initialize map with data java

I am stuck with ajax... I have a cart and it has gift vouchers, i) the code checks for valid voucher and if its not valid then it should show message "invalid voucher". ii) If voucher if valid and is ...

I am stuck with ajax... I have a cart and it has gift vouchers, i) the code checks for valid voucher and if its not valid then it should show message "invalid voucher". ii) If voucher if valid and is ...

  1. show message in view mvc
  2. show message in view laravel
  3. how to show message view in android studio
  4. show viewbag message in view
  5. show tempdata message in view
  6. show message from controller to view
  7. show error message in view mvc
  8. show error message in view from controller

JS models concurrency by an event loop. As a result there are no race conditions. So what are the drawbacks of the following type safe operation in the main scope of a program that would justify any ...

JS models concurrency by an event loop. As a result there are no race conditions. So what are the drawbacks of the following type safe operation in the main scope of a program that would justify any ...

  1. what is the typical class size at texas a&m
  2. what is the typical class size for ucla
  3. what is the typical class size at stanford university
  4. what is the typical class size at usc
  5. what are a typical class of anticancer drugs
  6. what is the typical class size at nyu
  7. what is the typical class size at texas tech
  8. what is the typical class size at asu
  9. what is the typical class size at unc
  10. what is the typical class size at gcu
  11. what is the typical class size at osu
  12. what is the typical class size at gsu
  13. what is the typical class size at pvamu
  14. what is the typical class size at wssu
  15. what is the typical class size at ttu
  16. what is the typical class size at csumb
  17. what is the typical class size at uc merced
  18. what is the typical class size at vsu
  19. what is the typical class size at apsu
  20. what is the typical class size at unr