Wednesday, August 22, 2012

Javascript, after if continues to else

For some reason after the if, it continues to else, except the ifs that take you to a different place, here is the code i have at the moment



<script type=\"text/javascript\">
function whatname(button) {
var post = prompt(\"Name?\", \"Visitor\")
if(post == \"Nick\"){
alert(\"Hi Nick\")
window.location = \"index.html\"
}
if(post == \"Visitor\"){
alert(\"Welcome Visitor\")
window.location = \"index.html\"
}
if(post == \"\"){
alert(\"Please Enter Name\")
}
if(post == null){
alert(\"Closing\")
}
if(post == \"show me a secret\"){
window.location = \"secret.html\"
}
if(post == \"Greg\"){
alert(\"Test\")
}
if(post == \"greg\"){
alert(\"Test 1\")
}
else{
alert(\"Welcome \" + post + \", Have Fun!\")
window.location = \"index.html\"
}
}
</script>


After the if happens, it continues to else, like let say i click cancel (which would be null) it would say, \”Closing\” but than another pop up would come up and would say, \”Welcome Null, Have Fun!\” than it would take me somewhere else, im not sure whats wrong, if you can help, it would be nice.






Rating: 3 out of 5 based on 8 ratings



The post Javascript, after if continues to else appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-after-if-continues-to-else.html

No comments:

Post a Comment