'javascript: how can I print an error message but only if there is already something in the text box
I have 2 text boxes. Inputs cannot match but I don't want error message to show up when they're both empty only when there has been something inputed in both boxes. how do I do this?
function validate() {
var errorMessage = "";
var textbox4Input = document.getElementById("fictional");
var textbox5Input = document.getElementById("real");
var textbox4 = textbox4Input.value.trim();
var textbox5 = textbox5Input.value.trim();
textbox4Input.value = textbox4;
textbox5Input.value = textbox5;
if (textbox4 === textbox5) {
errorMessage += "Favorite fictional place & favorite real place cannot be the same.<br>"
}
return errorMessage;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
