简体   繁体   中英

How to pass var values to a parameter in javascript?

I was trying to use 2 different tables, different input field, and different text in a single script. I use this script below to pass those values on a function parameter to get those values. The problem is I am not getting the input.value but I can get the input1.value . I think the input1 is not going inside the filterFunction(input) above

<script type="text/javascript">
    function filterFunction(table, input, total_amount_id) {
        var filter, tr, td, i, totalViewable = 0;
        console.log(input1.value);
        console.log(input);
        filter = input.value.toUpperCase();
        tr = table.getElementsByTagName("tr");
            for (i = 0; i < tr.length; i++) {
            td = tr[i].getElementsByTagName("td")[1];
            tds = tr[i].getElementsByTagName("td")[0];
            if (td) {
                if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                    tr[i].style.display = "";
                    totalViewable += parseFloat(tds.innerHTML);
                    document.getElementById(total_amount_id).innerHTML = "$" + totalViewable.toFixed(2);
                } else {
                    tr[i].style.display = "none";
                }
            }
        }
    }
    var table1 = document.getElementById("dateTable");
    var input1 = document.getElementById("event_date_range");
    var total_amount_id1 = "total_amount_td";
    filterFunction(table1, input1, total_amount_id1);
    var table2 = document.getElementById("dateTable2");
    var input2 = document.getElementById("event_date_range2");
    var total_amount_id2 = "total_amount_td2";
    filterFunction(table2, input2, total_amount_id2);
</script>
var input1 = document.getElementById("event_date_range"); 

In this expression you are placing value in input1 . so you cannot ge the {input} value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM