In the following code:
function Transact() {
if(document.getElementById('itctobuy').value!='') {
itctobuy = parseInt(document.getElementById('itctobuy').value);
}
if(document.getElementById('steamtobuy').value!='') {
steamtobuy = parseInt(document.getElementById('steamtobuy').value);
}
if(document.getElementById('reltobuy').value!='') {
reltobuy = parseInt(document.getElementById('reltobuy').value);
}
if(document.getElementById('airtobuy').value!='') {
airtobuy = parseInt(document.getElementById('airtobuy').value);
}
if(document.getElementById('bsnltobuy').value!='') {
bsnltobuy = parseInt(document.getElementById('bsnltobuy').value);
}
updateValues();
}
The function's executed by a simple onclick
of a button. There are 5 textarea elements and the user may input a number in any, and upon clicking the button the value should be stored in these vars if the textarea value isn't empty (Although it doesn't work even if the empty condition is not present).
If I remove the entire block, updateValues()
executes fine, whereas putting it back causes it not be executed, so the problem's with it. What's the reason for this and how do I fix this?
Edit: The console says the following:
Uncaught TypeError: Cannot read property 'value' of null at TRANSACT at HTMLButtonElement.onclick
So what's the cause of this error? It doesn't work when I input all text fields and their values are not null.