I have a javascript function in my asset tree. It takes the input from the user and then filters a table of data by that input. However, I cannot get it to work in my index.html.erb file from my asset/javascript pipeline. I can put the function in script tags in the index.html.erb page and it will work. I can also put an alert("test") in my javascript file and it will work in index.html.erb. Can someone take a look and tell me what piece I am missing?
// # Place all the behaviors and hooks related to the matching controller here.
$('document').ready(function(){
var stateInput, stateFilter, table, tr, td, i;
stateInput = document.getElementById("stateInput");
stateFilter = stateInput.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
function stateSearch() {
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(stateFilter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
});
Here is my index.html.erb. I only include the input tag because I am assuming it's all you need.
<input id="stateInput" type="textbox" placeholder="State ID ex. IN" onkeyup="stateSearch()">