If I have the following line at the top of my .js
file how come when I call a function that uses clickButton
it says it's null
?
In the HTML
<input type="text" onkeydown="toggle()" id="txt1" />
<input name="aButton" id="aButton" type="button" value="ButtonVal" />
In the JS
//global variables
var clickButton = document.getElementById("aButton")
var state = false
function toggle()
{
if(!state)
/*here it says clickButton is null but if I put var clickButton =
document.getElementById("aButton") in this scope it works*/
clickButton.disabled = true
else
clickButton.disabled = false
}
Also what is the difference (not how I check) between null and undefined? Is it that null has been declared but not assigned a value, where as undefined hasn't even been declared?
I mean this question says "A property to which a programmer has not assigned anything will be undefined, but in order for a property to become null, null must be explicitly assigned to it." but I can guarantee you that I never explicitly assigned null to anything.