javascript - Numerical values in web page -
i apologize if duplicate , realize rather broad. i'm having bit of trouble trying understand how approach following:
i want define numerical value , allow user click checkboxes number of sides , corresponding sides. after each successive side clicked value (number of sides) decrease , display updated amount in webpage.
how go this! define variables etc in jquery create functions check if checkboxes have been clicked decrease variable updating it. after how use variable in html portion(s) display number of sides remaining? understand html doesn't have variables. sorry if confusing i'm new web programming
correct, not able in html alone, can use jquery define variable total number of sides user select , decrease variable each time checkbox clicked(or increase if deselect it).
here's simple example started, expand on prevent user being able check more boxes if they've chosen limited number of sides.
$(document).ready(function() { var sidesremaining = 3; $('.sidesremaining').html(sidesremaining); $('input[type="checkbox"]').click(function() { if ($(this).is(':checked')) { // decrease total 1 sidesremaining -= 1; } else { // increase total 1 sidesremaining += 1; } $('.sidesremaining').html(sidesremaining); }); });
Comments
Post a Comment