vendredi 21 août 2020

Pass a group of IDs to function (onchange function)

I have 10 html table lines. In each line I have 1 checkbox and 2 input boxes, each element with an unique ID (AA, Price_1, RTprice_1, AB, Price_2, RTprice_2....AJ, Price_10, RTprice_10)

Trying to disable the corresponding input fields once a checkbox is checked. I'm repeating the function for each line. How can I pass each group of variable into the below function instead of having 10 functions? Script:

document.getElementById("AA").onchange = function() {
document.getElementById('price_1').disabled = !this.checked;
document.getElementById('RTprice_1').disabled = !this.checked;
document.getElementById('price_1').value = "0";
document.getElementById('RTprice_1').value = "0";
document.getElementById('AA').value = "0";
};  

                                       
document.getElementById("AB").onchange = function() {
document.getElementById('price_2').disabled = !this.checked;
document.getElementById('RTprice_2').disabled = !this.checked;
document.getElementById('price_2').value = "0";
document.getElementById('RTprice_2').value = "0";
document.getElementById('AB').value = "0";};



Aucun commentaire:

Enregistrer un commentaire