Javascript setinterval with cookie

801 Views Asked by At

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?

0

There are 0 best solutions below