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 6674513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:45:18+00:00 2026-05-26T03:45:18+00:00

I have a drop down selection box and using jQuery if statements i want

  • 0

I have a drop down selection box and using jQuery if statements i want to set a div element with some text, heres my code:

<select id="drop">
    <option value="Select">Choose an option...</option> 
    <option value="Blue" stock="0">Blue</option>
    <option value="Pink,15.00" stock="1">Pink</option>
    <option value="Red" stock="2">Red</option>  
</select>



$('#drop').change(function() {

   if ($(this).val() == 'Pink,15.00') { 
     $(".price-tag > span").text("Pink 15.00");
   }

  if ($(this).val() == 'Red') { 
     $(".price-tag > span").text("Red 5.00");
  }

  else {
     $(".price-tag > span").text("5.00");

  }  
});

The above code works fine when i select the Red option in the dropdown but it’s not working when the Pink is selected, i believe jQuery has problems with the if statement .val containing a comma or fullstop “Pink,15.00”.

A way i could get around this is by checking the text in the option, not the value. Not sure how to do this though, something like option:selected.

Help appreciated.

Thanks

  • 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-26T03:45:18+00:00Added an answer on May 26, 2026 at 3:45 am

    Add an else before the second if statement. Currently, the last else condition is always executed when the value is not red, overwriting the previously set “pink”.

    $('#drop').change(function() {
        if ($(this).val() == 'Pink,15.00') { 
           $(".price-tag > span").text("Pink 15.00");
        }
        else if ($(this).val() == 'Red') { //Add else!
           $(".price-tag > span").text("Red 5.00");
        }
        else {
           $(".price-tag > span").text("5.00");
        }  
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text box and a drop-down selection on a page, plus a
I have a drop down box I am using to change CSS using jQuery
I have a drop down select box inside a div. When the user clicks
So I have a drop-down list and a text-box: <table> <tr> <td>Group Name: </td>
I have a Drop down box Based on the selection i should populate the
I have a drop down box for each row inside a table <table> <tr>
I'm using the following chunks of code to populate a drop down box on
I need some help please, I have a PHP page with a drop down
So I am using jQuery UI's dialog box. But as I have a read
I have a drop down like this on my page: <p> <%= f.label :episode_id

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.