0
<input class='setupcheck' type='checkbox' data-x='xpslider'>
<input class='setupcheck' type='checkbox' data-x='xp323'>
<input class='setupcheck' type='checkbox' data-x='xp525'>  

I need for each checkbox to create a variable named as its data('x') and give it a value 1 if it is checked, else - value 0;

Something like this:

$('.setupcheck').each(function(){
    if ($(this).is(':checked')){
        variable named $(this).data('x') = 1;
    }
    else{
        variable named $(this).data('x') = 0;
    }
}
});

Any help?

2

1 Answer 1

2

If you want them global variables then use:

var storeObj = window;

$('.setupcheck').each(function(){
    if ($(this).is(':checked')){
        storeObj[$(this).data('x')] = 1;
    }
    else{
        storeObj[$(this).data('x')] = 0;
    }
});

Now check console.log(xpslider);

Or if you want to store them in separate then:

var storeObj = {};

and use as console.log(storeObj.xpslider);

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.