hello every one I'm trying to get better at programming and If you could help me that would be appreciated. What im trying to do is set a variable var easymode = false;
.. then i would like to check if the easymode option is chosen through a checkbox. im using the jQuery change() method so I could dynamically get a boolean value when the user clicks on and off the the boxes. inside the change method i want to change the value of easymode to true or false. I know I'm not doing it right if(easymode){ console.log('true'); }
doesnt turn true when easymode is checked.
code
$(document).ready(function(){
var easymode = false;
console.log(easymode)
$("input[type=checkbox]").change(function(){
if($(this).val() == "easy" && $(this).is(':checked')){
easymode = true;
}
else if($(this).val() == "easy" && !$(this).is(':checked')){
// alert('not easy mode');
easymode = false;
}
if($(this).val() == "hard" && $(this).is(':checked')){
alert('hard mode')
}
else if($(this).val() == "hard" && !$(this).is(':checked')){
alert('not hard mode');
}
})
if(easymode){
console.log('true');
}
)
});
Easy <input type="checkbox" id="justchange" value="easy"><br>
Hard <input type="checkbox" id="fullprice" value="hard">
<input type="text" id="textbox1">
Aucun commentaire:
Enregistrer un commentaire