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);     }); }); 

jsfiddle


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -