0

i have an dynamic array of multiple checkboxes. when i checked any checkbox then it get its value and put this in array. i want when i uncheck this then value of this checkbox remove from array. thnku..

$(document).ready(function (e) {
    var myCheckboxescolour = new Array();
    var myCheckboxesprice = new Array();
    var mycolour;
    var myprice;
    $(".searchcheck").click(function () {
        mycolour = '';
        myprice = '';
        if ($(this).attr('title') == 'colour') {
            if (this.checked == true) {
                myCheckboxescolour.push($(this).val());
            } else {
                if (jQuery.inArray($(this).val(), myCheckboxescolour)) {
                    myCheckboxescolour.pop($(this).val());
                }
            }
        })
    };
4
  • 6
    What does PHP have to do with this? Commented Oct 21, 2013 at 14:41
  • 2
    What's with the random "< br / >"? Commented Oct 21, 2013 at 14:42
  • i think this dosent belong there... Commented Oct 21, 2013 at 14:43
  • Why try to maintain the state of this array through the life of the page? Why not just build the array from the values when they are needed (like when the form is submitted, perhaps)? Commented Oct 21, 2013 at 14:45

1 Answer 1

1
var removeValue = $(this).val();

myCheckboxescolour = jQuery.grep(myCheckboxescolour, function(value) {
     return value != removeValue;
     });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.