Can someone please tell me why my code isn't working? I get the error: Cannot read property 'value' of null.
This is my html code:
<body onLoad="init()">
<input type="text" placeholder="User Name" id="id_inputuser"></input>
<label>Please Enter User Name</label><br>
<input type="text" placeholder="Password"id="id_inputpass"></input>
<label>Please Enter Password</label><br><br>
<button onClick="verify()">Enter</button>
</body>
And this is the JS:
function init()
{
var user= document.getElementById("id_inputuser").value;
function verify()
{if (user=="david")
{alert("working")}
else{alert("not working")};
}}
Any help will be highly appreciated :) Thanks a lot!
<input>Element exist at that time?var user= document.getElementById("id_inputuser").value;within your function. Also, inputs are self-closing.loginorinit.