When I was doing some JQuery and PHP,
I noticed the If-else patterns were treated differently and varied from one language to another
.
Say I got a simple input text field in a HTML
and I was using some Ifs and Elses to check the
value input into the text field.
Text: <input type="text" name="testing"/>
In JQuery, I got some codes as follows:
if($("#testing").val()==1){
//do something
}
if($("#testing").val()=="add"){
//do something
}
else{
//do something
}
if($("#testing").val()=="hello"){
//do something
}
How come JQuery and PHP treated the Else statement differently?
I mean in JQuery, the third If statement was
still proceeded even if it had gone to the Else statement,
but it stopped after the Else statement when I repeated the code in PHP script.
Your jQuery code is not how it should be, first of all, you are missing the id in your text field that you are checking in jquery:
And then you need
elseifstructure andelseshould go last:The
elseexecutes if none of the previous conditions resolved to true.