I'm attempting to create a javascript variable str. The ID idofnet may not exist, if it doesn't I want to ask for a value for str. If it does exist I want to pick it up from the ID. Here is my code...
function ics214button() {
if (typeof $("idofnet").html() === "undefined") {
var str = prompt("Enter a Log number.");
} else {
var str = $("#idofnet").html().trim();
}
if (str =="") {alert("Sorry no net was selected");}
else {alert ("It worked");}
}
When I test this knowing there is no ID = idofnet, I get the prompt to enter a log number. And the rest of the code executes properly. But when the idofnet does exist and it contains a value, I still get the prompt asking enter a log number. The value is never set in the else condition testing for undefined. If idofnet contains a value, why is it still asking me as if it were undefined? The var str will always be a number.