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

  • Home
  • SEARCH
  • 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 6358553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:23:53+00:00 2026-05-24T23:23:53+00:00

I am trying to check with jQuery if the select option with value =

  • 0

I am trying to check with jQuery if the select option with value = 1 is selected then add class to some elements. But something don’t work. Can please some one look at the code?

My code :

Reservation <br/>
<select id="rReservation" name="rReservation" class="">
                                <option value="0">Maybe</option>
                                <option value="1">Sure</option>
</select>
<hr/>
Name <br/>
<input type="text" name="rCardUser" class="mRequired" />

<hr/>
Card<br/>
<input type="text" name="rCardNrr" class="mRequired" />

jQuery

if ($("#rReservation").val() == "1") {
   $('.mRequired').addClass('required');
} else {
   $('.mRequired').removeClass('required');
}

LIVE example at fiddle – http://jsfiddle.net/C7Gg3/

  • 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-24T23:23:54+00:00Added an answer on May 24, 2026 at 11:23 pm

    You need it inside an event handler:

    $('#rReservation').change(function(){
        $('.mRequired').toggleClass('required', $(this).val() == '1');
    });
    

    http://jsfiddle.net/AlienWebguy/C7Gg3/1/

    If you want it to trigger simply on load, you need to add selected="selected" to one of the options, because until one is “selected”, $('#rReservation").val() will be null. Example: http://jsfiddle.net/AlienWebguy/C7Gg3/3/

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

Sidebar

Related Questions

I'm trying to check in jQuery if a div contains some text, and then
All, I'm removing some select options with jQuery using the following code: $('#other_liked_vendors option[value='
I'm trying to use jQuery to check for the existence of an <option> that
I am trying to achieve the following with jQuery: Select max 3 check boxes
HTML <select class=selectAddress name=select2 size=4 multiple=multiple> <option>address 1</option> <option>address 2</option> <option>address3, some city, uk</option>
I am trying to check checkboxes based on a select option. So, if the
I am trying to add a class to my tr rows if the select
I'm trying to check/unckeck a selectbox by jquery in a previous TD. I have
Basically all I'm trying to do is if one check box is selected by
I'm trying to speed up jQuery performance. I found some questions/answers on this site

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.