0
I have a script that when clicking on a specific option would call a function in javascript with onclick, but this script is only working in firefox desktop in other browsers does not work, I’ve been suspecting that the problem is being caused by using onclick in options, Is there any alternative way I can achieve what I want without using onclick? , you really shouldn’t use onclick in a select option?
My select:
<select class="custom-select" name="tamanho" id="tamanho" required="required">
<option selected value="Nenhum">Escolha...</option>
<option value="G" onclick="mostraG()">Grande (G)</option>
<option value="M" onclick="mostraM()">Média (M)</option>
</select>
My JS:
// Mostra M e oculta G
function mostraM(){
if (document.getElementById('pizzaM').style.display == "none"){
document.getElementById('pizzaM').style.display = "block",
document.getElementById('pizzaG').style.display = "none",
$("#sabor1G").val("Nenhum"),
$("#sabor2G").val("Nenhum"),
console.log("WORK");
}
}
// Mostra G e culta M
function mostraG(){
if (document.getElementById('pizzaG').style.display == "none"){
document.getElementById('pizzaG').style.display = "block",
document.getElementById('pizzaM').style.display = "none",
$("#sabor1M").val("Nenhum"),
$("#sabor2M").val("Nenhum"),
console.log("WORK");
}
}
Have you tried with
$('#tamanho').on.('change', function(){})
– adventistaam
Could you show me an example?
– YH Software
Yes. Just a moment
– adventistaam
What do you really need done in your select? If you want to perform a function when each option is selected the best option is onchange in select. https://answall.com/questions/365402/gostaria-de-saber-como-receber-o-valor-do-meu-select-ao-clicar-em-um-option-com/365408#365408
– user12100
https://answall.com/questions/238457/como-ativar-um-onchange-que-utiliza-options-de-um-select-via-javascript
– user12100