Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 846467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:37:08+00:00 2026-05-15T06:37:08+00:00

When I was doing some JQuery and PHP, I noticed the If-else patterns were

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:37:08+00:00Added an answer on May 15, 2026 at 6:37 am

    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:

    <input type="text" name="testing" id="testing" />
    

    And then you need elseif structure and else should go last:

    if($("#testing").val()==1){
    //do something
    }
    else if($("#testing").val()=="add"){
    //do something
    }
    else if($("#testing").val()=="hello"){
    //do something
    }
    else{
    //do something
    }
    

    The else executes if none of the previous conditions resolved to true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some help converting this from prototype to jQuery. I'm doing some
I'm doing some shennanigans with jQuery to put little plus/minus icons next to my
I'm doing some PHP stuff on an Ubuntu server. The path I'm working in
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I've been doing some HTML scraping in PHP using regular expressions. This works, but
This should a quick question for some easy rep. I'm doing some PHP Website
After doing some work with Ruby, Rails, and RSpec last summer and I learned
I'm doing some funky authentication work (and yes, I know, open-id is awesome, but
I am doing some research on Unicode for a white-paper I am writing. Does
I've been doing some mocking with RhinoMocks and it requires that mocked methods be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.