0

I have some problem. I have select option with value and keep selected(values) with jscookie, i want to add auto refresh feature to the select option then i choose setInterval to manage it, the jscookies didn't working to keep selected value.

here is my codes :

// create Cookie Select PIC Picklist
$('#selectPicker').change(function() {
      if( Cookies ) {
          Cookies.set('pic', $(this).val());
      }
});

var value = Cookies && Cookies.get('pic') || '';
$('#selectPicker').val(value).trigger('change');

setInterval(function(){
    $("#selectPicker").load('localhost/picklist/data/pic')
}, 2000);

and the select option :

<select id="selectPicker" name="picker" required/>
</select>

and the load data from localhost/picklist/data/pic :

<option value="">Pilih PIC Picker</option>
<option value="2">Indra</option>
<option value="3">Maulana</option>
<option value="4">Nayla</option>

anyone can helping out?

Paladin
  • 1,637
  • 13
  • 28
  • You're calling `$('#selectPicker').val(value)` before the `localhost/picklist/data/pic` data is loaded, before the `option`s are added to the `select` element. – Titus Dec 14 '17 at 07:55
  • Try `$("#selectPicker").load('localhost/picklist/data/pic', function(){$('#selectPicker').val(value);})` – Titus Dec 14 '17 at 07:55
  • Hi @Titus, thank you, i have test the code from you, now its working fine. – Kazuya Marino Dec 14 '17 at 08:18

0 Answers0