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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:17:54+00:00 2026-06-06T22:17:54+00:00

When user select United States I show textbox for US city but what if

  • 0

When user select United States I show textbox for US city but what if user deselect the United States?

How could I check if there is United States selected or not if not the hide City textbox.
enter image description here
my script is:

<tr>
<td nowrap="nowrap">
<label for="countryId">Countries</label>
</td>
<td>
<select id="countryId" onchange="usCity();" multiple="multiple" name="countryId[]">
<option value="1">United States</option>
<option value="2">United Kingdom</option>
<option value="3">Australia</option>
<option value="4">UAE</option>
<option value="5">Denmark</option>
<option value="6">Czech Republic</option>
<option value="7">Brazil</option>
<option value="8">Singapore</option>
<option value="9">Pakistan</option>
<option value="10">Germany</option>
<option value="11">India</option>
<option value="12">SriLanka</option>
<option value="13">UK</option>
<option value="14">Algeria</option>
<option value="15">Andorra</option>
<option value="16">Caneda</option>
<option value="17">HongKong</option>
</select>
</td>
<td valign="top">
</tr>
<tr id="usCitytr" style="display: none;">
<td nowrap="nowrap">
<label for="USCity">US City Name</label>
</td>
<td colspan="3">
<input id="USCity" type="text" value="" name="USCity">
</td>
</tr>

function usCity()
    {
        if ($("#countryId option:selected").text() == 'United States' || $("#countryId option:selected").text() == 'US'){
            $("#usCitytr").show();
        }
    }

I thing on each selection I have to get all selected values in array structure and then using loop to find ‘US’ if found then show ‘US City’ textbox else hide. For this I used

alert($('select#countryId').text());

but it returns all values present in combobox. How ever

alert($('select#countryId').val());

returns only selected value but I need ‘US’ not the index where ‘US’ is present because ‘US’ might be any where.

  • 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-06-06T22:17:55+00:00Added an answer on June 6, 2026 at 10:17 pm
    <option id="opt_US" value="1">United States</option>
    
    
    if ($("#opt_US").is(":selected") {
        $("#usCitytr").show();
    } else {
        $("#usCitytr").hide();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If user select an option from dropdown it will shown it a textbox but
I know how to let user select an image from UIImagePickerController, but I don't
i want to check image size once user select an image from gallery.Because big
Is there a way to let the user select which device they use for
I want to make user select only one component. Is there a way to
I have a windows form and user select cloth parameters from comboboxes like country-state-city
I've tried setting -webkit-user-select: none and selectstart And it did remove the selector, but
I have the application in which user select the particular folder and all the
I have developed a application in which user select the particular folder and it
I have developed a application in which user select the particular folder and it

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.