JSFiddle - React, Tailwind, and code Playground

by Pevara

HTML

<select id='interval'>
    <option value='1000'>1 sec</option>
    <option value='5000'>5 sec</option>
    <option value='10000'>10 sec</option>
    <option value='15000'>15 sec</option>
</select>

<ul id='result'>
</ul>

JavaScript

// when the interval selector changes
$('#interval').change(function() {
   // remove the old timer 
   window.clearInterval(refresher);
   // set a new timer based on the selection
   refresher = window.setInterval(doSomething, parseInt($(this).val()));
});

// your ajax call should be in here probably
function doSomething() {
   $('#result').append($('<li>I did something!</li>'));   
}

// start the interval on load with some default value
var refresher = window.setInterval(doSomething, 3000);