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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:48:37+00:00 2026-05-19T00:48:37+00:00

<select name=state class=select id=state> <option value=something>Something</option> <option value=other>Other</option> </select> <input type=text name=province class=text id=province

  • 0
<select name="state" class="select" id="state">
    <option value="something">Something</option>
    <option value="other">Other</option>
</select>

<input type="text" name="province" class="text" id="province" />

jQuery

$('#state').change(function () {
    if ($('#state Other:selected').text() == "Other"){
        $('#province').attr('disabled', false);
        alert(1);
    } else {
        alert(2);
    }
});

Doesn’t seem to work. I must be doing something wrong.

  • 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-19T00:48:38+00:00Added an answer on May 19, 2026 at 12:48 am

    You should use .removeAttr('disabled') instead of .attr('disabled', false). Also you should cache your jQuery selectors.

    Edit: Thought about this after the fact. You may want to “empty” the text that had been typed into the field if you are disabling it, so I added a .val(''), if you also wanted to hide it, you could add .hide() and .show() to the two cases.

    I put together this fiddle to show you a working version:

    var $state = $('#state'), $province = $('#province');
    $state.change(function () {
        if ($state.val() == 'other') {
            $province.removeAttr('disabled');
        } else {
            $province.attr('disabled', 'disabled').val('');
        }
    }).trigger('change'); // added trigger to calculate initial state
    

    The .trigger('change') will “trigger” a change event, effectively running the function once while you bind it. This way, the #province will be either disabled / enabled based on the state selected at the time the code is run. Without it, the province would have been available even if the state isn’t “other” unless you also added disabled='disabled' to the <input> tag in your html.

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

Sidebar

Related Questions

<select name=state class=input-small selected=<? if(isset($_SESSION['user'])){ echo $row_login['state']; }?>> <option value=AL>AL</option> <option value=AK>AK</option> <option value=AZ>AZ</option>
Given the following: <div class=filters id=filters> <select id=state name=state tabindex=1 > <option value=>Filter by
I tried this: http://jsfiddle.net/ilyaD/KGcC3/ HTML: <select name=state class=ddList> <option value=>(please select a state)</option> <option
I have three select boxes state,city and locality with the id's same as name
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'myTrigger' AND type = 'TR')
Let's say I have SELECT name FROM table which gives me something like foo
Searching for values that uses the same value Example SELECT Name, UnitPrice, Quantity, Color
I call a javascript function that dynamically builds <li> 's with a text input
SELECT name FROM sys.databases -- this can list all database name in the server
For example: select name from person where id=2; I wand to know if this

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.