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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:11:30+00:00 2026-06-09T15:11:30+00:00

I have a drop down list (yii framework) , that i would like to

  • 0

I have a drop down list (yii framework) , that i would like to change its selected value.
this is the drop down list :

<?php
                $t = is_null($dataProvider[$key]['room']) ? 'NA' : $dataProvider[$key]['room'];

                echo 'Room Number : ' . CHtml::dropDownList(Rooms::model(), 'roomID', CHtml::listData(Rooms::model()->findAll(array(
                                    'condition' => 'status = :status or roomID = :roomID',
                                    'params' => array(
                                        ':status' => 'ready',
                                        ':roomID' => $dataProvider[$key]['room']
                                    )
                                )), 'roomID', 'roomID'), array('id' => 'room', 'class' => 'ui-widget-content', 'empty' => 'NA',
                'options' => array($t => array('selected' => true))))
                ;
                ?>

Now this drop down list is a child of a parent that i would like to clone so i can use it again , so i used this to clone it:

var test =$("#users-contain").children(':last').clone(true,true);
        test.children("#room option[value='3']").attr('selected', 'selected');
        test.children('table').children('tbody').children('tr').empty();
        var inner = test.clone(true,true);

I will use the var inner to change a few things in the element and clone it on the page.
Now here is my problem , For my new clone which is the var test , i would like to change the drop down list’s selected value , but it doesn’t work at all,i tried this :

test.children("#room option[value='3']").attr('selected', 'selected');

and this :

test.children('#room').val(3);

Nothing works,i also tried other things that i don’t remember,however i should note that using the last one , when i debug it with :

console.log(test.children("#room").val());

it outputs a value of ‘3’ which is correct , however when i display it on the page , the selected value of the old drop down list doesn’t change.
this is the result:

<select id="room" class="ui-widget-content" name="">
<option value="">NA</option>
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>

Thank you in advance.

  • 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-09T15:11:31+00:00Added an answer on June 9, 2026 at 3:11 pm

    The line test.children("#room option[value='3']").attr('selected', 'selected') has the basic idea, but children gets the children elements only and filters them. So it would get #room, but it wouldn’t get the option elements because the <option>s are grandchildren of test. Instead, use find, which searches through all descendant elements. Here’s the code:
    test.find("#room option[value='3']").attr('selected', 'selected')

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

Sidebar

Related Questions

I have a drop down list's select tag that looks like this: <select name=MyName
I have a drop down list <select onchange=alert(this.value);> <option selected=selected value=cat>cat</option> <option value=dog>dog</option> </select>
I have a drop down list and I want the selected value to put
I have this drop-down list of countries: <select name=country> <option value=>Country...</option> <option value=Afganistan>Afghanistan</option> <option
I have a drop-down list of colors, and when selected, i want to change
I have a drop down list and would like to remove an option from
I have a client who would like to have drop down list added to
Suppose I have a drop-down list like: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option
I am doing a yii web application i have a drop down list that
I have a drop-down list that I need to capture the value of when

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.