0

When I run this code, the if statement under onClick evaluates when view.checked == true, but the else does not evaluate when view.checked == false. The alert shows that view.checked seems to be working properly. No idea what's going on. I'm using these two plugins:

https://datatables.net/ with fnFilter plugin

and

http://wenzhixin.net.cn/p/multiple-select

As a side note, also trying to figure out why my .join() method adds spaces.

var checked = [];
var checkedreg = '';
$(document).ready(function() {
    rtable = $('#ropes').dataTable( {
        "ajax": "data/ropes.txt",
        "dom": 'C<"clear">lfrtip',
        "columns": [
            { "data": "brand" },
            { "data": "model" },
            { "data": "length" },
            { "data": "dia" },
            { "data": "price" },
            { "data": "drytreat" },
            { "data": "midmark" },
            { "data": "bipat" },
            { "data": "falls" },
        ],
    });
    $('select').multipleSelect({
       onClick: function(view) {
        checkedreg = ''; 
        alert(view.checked);
        if (view.checked) { //if checkbox is checked
                checked.push(view.label); //add value of checkbox to "checked" array (ex. "Petzl")
            } 
            else {
                checked.splice(array.indexOf(view.label), 1); //if checkbox is not checked, remove value from array
                alert(checked); //test
            }
            checkedreg = checked.join("|"); //create regex of values ("Petzl| Mammut| Edelweiss)"
            checkedreg = checkedreg.replace(/\s+/g, ''); //for some reason it adds spaces so i have to remove them
            alert(checkedreg); //test
            alert(checked); //test
            rtable.fnFilter(checkedreg, 0, true); //filters a column based on a regex and column index
        }
    })
});
3
  • What does alert(view.checked); say? Also, what does your JavaScritp console say? Commented May 8, 2014 at 20:51
  • Still trying to identify the root problem. I can tell you though, you've got an extra brace } near the bottom of the $('select').multipleSelect({... code. You're also missing the closing semicolon ; on the end of that same code block. Commented May 8, 2014 at 20:51
  • you probably need to explicitly set a check what view.checked equals when its true and not when its false Commented May 8, 2014 at 20:53

1 Answer 1

2

Replace checked.splice(array.indexOf(view.label), 1); with checked.splice(checked.indexOf(view.label), 1); and try

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.