emsoff
emsoff

Reputation: 1605

Fire a change function without changing focus

I have a table that is sortable and filterable, and everything works fine if I change my filter using a select field. But, if a user doesn't select a filter after x number of seconds, I want it to filter based on a designated option. I have no problem changing the selection after a set time, but the javascript to filter doesn't recognize this is a change() event. How can I get it to recognize it as a change, or by some other way register the default selection after a set period of time?

For reference, I'm using this script for the table filtering/sorting:

http://www.javascripttoolbox.com/lib/table/

I'd like to pass it my own values for Table.filter(this,this).

Upvotes: 0

Views: 90

Answers (2)

Samuel Reid
Samuel Reid

Reputation: 1756

HTML:

<select id="select" onchange="Table.filter(this,this)">... </select>

Javascript:

var select = document.getElementById("select");
var secondsToChange = 2;

select.onclick = function() {
  window.setTimeout(function(){select.onchange.apply(select)},secondsToChange*1000);
};

I think that should work...

Upvotes: 0

Barmar
Barmar

Reputation: 780974

I think something like this should work:

var defaultFilter = 3;
var filterTimeout = 5000;

window.setTimeout(function() {
    var select = document.getElementById("select");
    select.selectedIndex = defaultFilter;
    Table.filter(select, select);
}, filterTimeout);

Upvotes: 1

Related Questions