(simple) return in if statement?
Code:
if(customer== ""){
document.getElementById('customerInfo').innerHTML = "";
return;
}
In this code, Why is the RETURN there? It doesn't work without the return, and it doesn't matter if i put return false, or return true.. (full code underneath)
Code:
function toonKlant(klantnaam){
if(klantnaam == ""){
document.getElementById('hint').innerHTML = "";
return;
}
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("hint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','toonklant.php?name=', true);
xmlhttp.send();
}
Originally Posted by
notflip
Code:
if(customer== ""){
document.getElementById('customerInfo').innerHTML = "";
return;
}
In this code, Why is the RETURN there? It doesn't work without the return, and it doesn't matter if i put return false, or return true
It's just a cheap and unclear way of aborting the function if the required data hasn't been passed.
Having said that, this code seems to be making a request without appending the required data:
Code:
xmlhttp.open('GET','toonklant.php?name=', true);
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
I copy pasted before the code was ready =) thanks for the response..
what would be a good way to abort the function if false? thanks!
Originally Posted by
notflip
what would be a good way to abort the function if false? thanks!
In this case, don't allow the function to be called without a parameter.
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks