How to solve a Firefox problem with if statements

How to solve a Firefox problem with if statements

MickManMickMan Posts: 27Questions: 4Answers: 0
edited June 2021 in General

Hi everyone,

first of all, sorry for my english and sorry if this is the wrong place or it's just a stupid post.

I want to share the solution for a problem that i was facing with firefox only.

I had this piece of code that works for Chrome and Safari (dunno about Explorer/Edge):

function modificaquantitaprezzo(){
var inputNome = document.getElementById("inputnome").value;
var inputVal = document.getElementById("inputisin").value;
var inputQta = document.getElementById("inputquantita").value;
var inputPrz = document.getElementById("inputprezzo").value.replace(',','.');
var modificaID = id;
fetch(https://API-URL?user=<?php echo $slusername_html; ?>&isin=${inputVal}&qta=${inputQta}&prezzo=${inputPrz}&nome=${inputNome}&id=${modificaID}&action=2).then(function(response){
return response.text().then(function (text) {
if (text === "NOT FOUND"){
alert( inputVal + " non trovato");
};
if (text === "OK"){
alert( "Quantità e prezzo di " + inputVal + " modificati con successo");
};
if (text === "EXIST"){
alert( inputVal + " già presente nel portafoglio personalizzato");
}
});
});
parent.location.href=parent.location.href;
}

In Firefox this code won't work and doesn't fetch the api url (to edit the record) nor pops up the alert.

The solution is to add the page refresh (can't call a table redraw for other reasons) to any if statement:

function modificaquantitaprezzo(){
var inputNome = document.getElementById("inputnome").value;
var inputVal = document.getElementById("inputisin").value;
var inputQta = document.getElementById("inputquantita").value;
var inputPrz = document.getElementById("inputprezzo").value.replace(',','.');
var modificaID = id;
fetch(https://API-URL?user=<?php echo $slusername_html; ?>&isin=${inputVal}&qta=${inputQta}&prezzo=${inputPrz}&nome=${inputNome}&id=${modificaID}&action=2).then(function(response){
return response.text().then(function (text) {
if (text === "NOT FOUND"){
alert( inputVal + " non trovato");
parent.location.href=parent.location.href;
};
if (text === "OK"){
alert( "Quantità e prezzo di " + inputVal + " modificati con successo");
parent.location.href=parent.location.href;
};
if (text === "EXIST"){
alert( inputVal + " già presente nel portafoglio personalizzato");
parent.location.href=parent.location.href;
}
});
});
}

I hope this can help someone who's facing a similar problem with Firefox.
Again, sorry if this is just a dumb post. Feel free to delete it if it's a nonsense.

Sign In or Register to comment.