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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:12:28+00:00 2026-06-12T11:12:28+00:00

I have really put efforts in searching for possible answers here and on Google.

  • 0

I have really put efforts in searching for possible answers here and on Google. I did find some answers but when I apply them to my code and my situation, it just doesn’t work.

I tried:

$("select#city option['City, ST']").attr('selected', 'selected');

I also tried:

$("select#city").val('City, ST');

as suggested somewhere.

I tried putting this code to a document.ready function – to no avail. I then tried placing it at the top (not in the head section though) with no document.ready but still the same.

What could be the reason for this function to fail? Is the moment when it’s called important (I mean, does it matter if my select box with values render first and then the function gets called? Or could it be something else?

HTML code:

<div class="ui-widget">
            <h3>Location</h3>
            <form id="chooseCity" class="" action="" method="post">
                <select id="city" name="city">

                    <option value="Select Town">Select Town</option>
                    <option value='Acworth, NH'>Acworth, NH</option>
                    <option value='Alstead, NH'>Alstead, NH</option>
                    <option value='Alton, NH'>Alton, NH</option>
                    <option value='Alton Bay, NH'>Alton Bay, NH</option>
                    <option value='Amherst, NH'>Amherst, NH</option>
                    <option value='Andover, NH'>Andover, NH</option>
                    <option value='Antrim, NH'>Antrim, NH</option>
                    <option value='Concord, NH'>Concord, NH</option>
                </select>
            </form>
        </div>

Could this loop be the culprit? Maybe it’s somehow interferring:

                <option value="Select Town">Select Town</option>
                    <?php foreach($arr as $city):
                        echo "<option value='{$city}'";
                        echo ($_POST['city-hp'] == $city) ? 'selected' : '';
                        echo ">".$city."</option>".PHP_EOL;
                    endforeach; ?>

IMPORTANT EDIT:

I’ve discovered that this piece of code:

$(function() {
    $( "#city" ).combobox();
    $( "#toggle" ).click(function() {
        $( "#city" ).toggle();
    });
});

is preventing my combobox to programmatically select desired value.
But this piece of code is crucial for styling the select box. I’ve downloaded the example from the jQuery UI website and integrated it into my website.

How can the above code be modified to retain its appearance while allowing for the desired functionality?

  • 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-12T11:12:29+00:00Added an answer on June 12, 2026 at 11:12 am

    Your jQuery works – something else is interfering.

    I would suggest poking through other plugins you may have installed to see if they’re overriding the selected index, probably just with the first <option> in the select.
    Alternatively, if you want to elaborate on which technologies you’re using, someone might be able to help you further.

    Edit:

    See the answers on this related question – it looks like you will have to edit the plugin’s source.

    Find this line in the combobox plugin:

    .addClass("ui-widget ui-widget-content ui-corner-left");
    

    and add this line immediately after it:

    input.val( $(select).find("option:selected").text());
    

    Source

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

Sidebar

Related Questions

I have really put in significant efforts to somehow find an answer; having failed
I really have no idea what I did to cause this exception, but I
I'm using Filemaker Pro 12 Advanced. I have a few tables but have really
I have a clojure application that need some configuration variable, mainly string but also
I have really odd user requirement. I have tried to explain to them there
Here are my questions: 1) Have you tried to put all the data only
I have a really small app that I put together in VS 2008 Express
I have a need to bind some HTML to an object, but my issue
I have been programming for the past 3 years and haven't really put in
My question does not really have much to do with sqlalchemy but rather with

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.