So this seems like a simple question but the following code works but not as I expect This is an example from an online video checking for http in a field. I know there are other questions about the 'correct' way to use indexOf but my question is why this code works.
document.ucDivIntake.website.onchange = function(){
var theURL = document.ucDivIntake.website.value;
if(theURL.indexOf("http")){
document.getElementById('errorMessage_website').innerHTML = "need http";
document.getElementById('errorMessage_website').style('display', 'inline');
}
}
This does display the error message if http is not present. If http is not found by indexOf it returns -1. I confirm that in my ide debugger. So would that fail the condition and not enter the condition code. Seems like I am missing something basic.