JSFiddle - React, Tailwind, and code Playground
by Damith Nuwan Sampath
HTML
<input id="filter1" type="text"/>
<input id="filter2" type="text"/>
<input id="filter3" type="text"/>
<div id="jsonFilterLength"> </div>
<div id="filterTest"> </div>
JavaScript
var jsonFilter = [];
$("input:text[id^='filter']").live({
focusin: function () {
currentFilter = $(this).val();
$(this).removeClass("filter");
$(this).val("");
},
focusout: function () {
if ($(this).val() == "") {
// If they gave up focus and didn't type anything in the box, restore the text
$(this).addClass("filter");
$(this).val(currentFilter);
}
},
keyup: function () {
jsonFilter = [];
$("input:text[id^='filter']").each(function () {
if ($(this).val() != "" && !$(this).hasClass('filter')) {
//alert("filterBy: " + $(this).attr('id') + "\nfilterValue: " + $(this).val());
jsonFilter.push({ filterBy: $(this).attr('id'), filterValue: $(this).val() });
}
});
//alert("Done with .each()");
filterReport(jsonFilter);
return true;
}
});
function filterReport(_jsonFilter) {
//alert(_jsonFilter.length);
$("#jsonFilterLength").html(_jsonFilter.length);
//$("#filterTest").html("");
for (var i = 0; i < _jsonFilter.length; i++) {
$("#filterTest").append("Index: " + i + ", filterBy: " + _jsonFilter[i]["filterBy"] + ", filterValue: " + _jsonFilter[i]["filterValue"] + "<br /><br />");
}
}