I think I got the Title right but here is what I want to do
$(document).ready(function(){
var oVars = {};
var withones;
etc //didnt work in what of my attempts to declare variables here so didnt cont.
$('.checkboxes :checkbox').click(function(){
var $this = $(this);
if($(this).is(':checked')){
oVars[this.id] = true;
console.log( oVars)
}
if(!$this.is(':checked')){
oVars[this.id] = false;
console.log( oVars)
}
at this point it is to my understanding that the oVars is like
oVars{
withones : true,
withoutOnes : false, //if unchecked
dispReg :true //if checked
}
I see the values of the properties change when I check the boxes
I want to be able to do something like this (globally):
var withOnes = oVars['withones'];
var withoutOnes = oVars['withoutOnes'];
etc;
I want to declare these variables globally and I want their values to change according to true or false because that is what is being assigned in the if $(this).is(':checked') to demonstrate which one is checked. The reason why I want to do this is that i want to make a function where the argument is the updated value.
});
I would make a code like below somewhere else in the code
if(withOnes){ // I want withOnes to be true if checked false if unchecked
process code if true
}
I tried to do something like below. please help me figure out how to change these variables value so I could use the variable other places in the code
if(withones = true){
console.log("withones checked")
}
if(withones = false){
console.log("withones unchecked")
}
but only "withones checked" was displayed every time the checkbox was changes.
});
HTML:
<div>
<div class="checkboxes">
<div class="dificulty">
<label for="withones" class="labelOuter" >
<input type="checkbox" id= "withones" class = "regular-checkbox big-checkbox"><label for="withones"></label> <span class="label">With ones</span>
</label>
<label for="withoutOnes" class="labelOuter" >
<input type="checkbox" id = "withoutOnes" class= "regular-checkbox big-checkbox"><label for="withoutOnes"></label><span class="label">Without ones</span>
</label>
</div> <!-- dificulty -->
<div class="view">
<label for="dispReg" class="labelOuter" >
<input type="checkbox" id = "dispReg" class= "regular-checkbox big-checkbox"><label for="dispReg"></label><span class="label">Display cash register</span>
</label>
<label for="hideReg" class="labelOuter" >
<input type="checkbox" id = "hideReg" class= "regular-checkbox big-checkbox"><label for="hideReg"></label><span class="label" title ="gets rid of image">hide cash register</span>
</label>
<label for="hideItems" class="labelOuter" >
<input type="checkbox" id = "hideItems" class= "regular-checkbox big-checkbox"><label for="hideItems"></label><span class="label">hide items</span>
</label>
<label for="showItems" class="labelOuter" >
<input type="checkbox" id = "showItems" class= "regular-checkbox big-checkbox"><label for="showItems"></label><span class="label">show items</span>
</label>
</div> <!-- view -->
</div>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire