0

HTML:

<select data-placeholder="Choose a Travel Agency..." class="chosen-select fc-inputbox travel-agency-dropdown" id="travel_agency_id">
    ... foreach
</select>

Javascript:

var data = {
    id: row.find('td:first-child').text().trim(),
    travel_agency_name: row.find('td:nth-child(2)').text().trim(),
};
var select_travel_agency = $('.travel-agency-dropdown:first').clone().attr('id', 'travel-agency-id-'+data.id).val(data.travel_agency_name).trigger("chosen:updated");

I've already created the travel agency and what i wanted is to update it while setting the SELECT default value of the agency. The reason why i cloned it is for me to get the datas and without calling another GET

Ebuen Clemente Jr.
  • 157
  • 1
  • 2
  • 13

1 Answers1

0

Can you use jQuery's change function? Example:

<select class="target">
    <option value="option1" selected="selected">Option 1</option>
    <option value="option2">Option 2</option>
  </select>
$( ".target" ).change(function() {
  alert( "Handler for .change() called." );
});

So you will just have to write:

var clonedSelect = $('#travel-agency-id-'+data.id);
clonedSelect.change(function(){alert('second select changed his value to ' + clonedSelect.val());});
Maurizio Ricci
  • 462
  • 1
  • 4
  • 11
  • yep i can use the change.. but im using the CHOSEN select link -> https://harvesthq.github.io/chosen/options.html – Ebuen Clemente Jr. May 01 '17 at 08:59
  • what i wanted is when the user clicks the update, he's able to see the default value of the selected travel agency.. – Ebuen Clemente Jr. May 01 '17 at 09:01
  • It's not very clear what you want to do...if you want to "read" the value of the first select in order to fill the second select with appropriate values, you can do as follows: read the value using .val(), then fill second select with values as shown in this answer http://stackoverflow.com/a/14447147/6726261 – Maurizio Ricci May 01 '17 at 13:35