Seeking guidance on a perplexing issue.
Here is a basic code snippet to depict my dilemma:
html:
<form>
<input type="number" id="someNumber">
<input type="button" id="submitBtn">
</form>
jquery:
$("#submitBtn").click(function() {
var numberValue = $("#someNumber").val();
if(numberValue.trim() == "") {
$("#someNumber").attr("class", "inputError");
}
});
css:
.inputError {
border: 1px red solid;
}
The problem I am facing is that, even if the input value is "asd", jquery is flagging it as an error because numberValue.trim() == ""
evaluates to true. This is puzzling, as I only intend to check if the input field is empty. Any suggestions on how to resolve this issue would be greatly appreciated.