In my application, I am taking a value for username. If that value is 0, then I have to run some code. But how should I write the if block?
var userName=document.getElementById("member").value;
The above statement will return 0 (zero). Can anybody write the if statement for me? Thank you in advance.This is the entire code
var userName=document.getElementById("member").value;
var password=document.getElementById("password").value;
if(userName==="0"){
var div4 = document.getElementById("errorMessage");
var text1 = "insert userName.";
div4.style.display = "block";
div4.style.color = "red";
div4.style.fontSize = "65%";
div4.innerHTML = text1;
Additional to the other answers: you could check for the value 0 this way
With the advantage that if the user fills the username field with whitespace only (spaces, tabs etc) it will still evaluate to
true(that’s because the Number conversion trims the parameter value).