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);
}
}
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);
}
}
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("/...
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 ...
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 ...