Forums

How to select Dropdown option

thebatik 03 May, 2018
I'm trying to select first <option> from dropdown using jQuery.

In this case absolutely nothing changes:
$("#select_id input:radio:first").attr('checked', true);

In this case, the classes "active" and "selected" were added and cleared at once.
And <option> wasn't selected.
$('div.item:nth-child(1)').addClass("active selected");
healyhatman 03 May, 2018
jQuery('dropdownselector').val(val).change();
jQuery('dropdownselector').closest('dropdown').dropdown('refresh');
thebatik 04 May, 2018
I've used it already, but without success.

I'll try to describe my situation:

- I have a radios group and dropdown list (is hidden)

- default list is empty


- when you select the radio button, show the dropdown list tablesize




- in this code:
1) clear the dropdown list
2) append <option> from array
3) set value to dropdown
4) try to refresh dropdown
var table_size_article_1 = { "a_50×23": 374, "a_60×27": 527, "a_70×32": 728 };

$('input[name=tableview]').on("change", function() {

$("#tablesize").empty();

$.each(table_size_article_1, function(name, values){
$('#tablesize').append($('<option>', {
value: values,
text: name
}));
});

$("#tablesize").val(values).change();
$("#tablesize").closest('dropdown').dropdown('refresh');
});

In result, value was set to dropdown. But still no selected.

If I comment //$ ("# tablesize"). Empty(); then the dropdown list will be selected after selecting the radios group twice (for example first radio button and second).
thebatik 04 May, 2018
Here's what I noticed:
- the hidden <select> has an active <option>
- and <div> class "text" is empty



Somebody know, how I can refresh data in <div class="text"> ?
GreyHead 05 May, 2018
Hi thebatik,

Please check the Dynamic Loading section on page 37 of the CFv6 manual - I think that this will do what you need here.

Bob
thebatik 05 May, 2018
Hi Bob!

Please see to my picture (sorry, but i'm not a designer)

I see that original <select> working correct after method "append" only and I needn't to "refresh" function.


My js code contains in js file and checkbox "Add inside" is unchecked. Right?
GreyHead 06 May, 2018
Hi thebatik,

It looks to me as if you have two drop-downs, one inside the other. Please check my last post for another way to do this.

Bob
This topic is locked and no more replies can be posted.