I want to change the max attribute for an input element in HTML by checking or unchecking a checkbox by using the onchange attribute in HTML and Javascript. However, the code that I have written does not change the max attribute and the default value remains the same when I check the relevant box.
I want to call the Javascript function max_events() when I check or uncheck the box (first code snippet) and I want it to change the max attribute in the second code snippet.
<input type="checkbox" name="generatorOUT" id="generatorOUT" onchange="max_events(this);"> generator<br>
<input type="number" name="nevents" id='box2' oninput="calculate();" min="1" max="10000" required></td>
Here is my max_events function:
function max_events(checkboxElem) {
if(document.getElementByID('generatorOUT').checked)
document.getElementByID('box2').max = "1000";
else document.getElementByID('box2').max = "10000";
}
Aucun commentaire:
Enregistrer un commentaire