javascript - Summing Int of Range and blocking Range when maximum is reached -
so i'm trying script character generator of rpg , want people set stats. these stats can go 1 10 each. user uses regular html ranges set them. i'm summing these until user reaches 18 points overall. issue here is, don't know how stop the rages go when 18 points hit. i'm summing stats this:
<fieldset id="attribute" oninput="streight.value=parseint(staerke.value);wisdom.value=parseint(weisheit.value);agility.value=parseint(geschick.value);apwert.value=parseint(staerke.value)+parseint(weisheit.value)+parseint(geschick.value)+' / 36'"> <legend>attribute</legend> <label for="staerke">stärke</label> <input type="range" id="staerke" value="1" min="1" max="10"> <output name="streight" for="staerke">1</output> <label for="weisheit">weisheit</label> <input type="range" id="weisheit" value="1" min="1" max="10"> <output name="wisdom" for="weisheit">1</output> <label for="geschick">geschick</label> <input type="range" id="geschick" value="1" min="1" max="10"> <output name="agility" for="geschick">1</output> <output name="apwert" id="apwert" for="ap">3 / 18</output> </fieldset>
this counting values of range-inputs, summing them , showing them in output without page reload. have no idea how stop range-inputs when maximum of 18 reached. i'd thankful kind of help.
you validation runs each time input of of 3 inputs changed. this:
in html
<input type="range" id="staerke" value="1" min="1" max="10" onchange ="value_changed()"> <input type="range" id="weisheit" value="1" min="1" max="10" onchange ="value_changed()"> <input type="range" id="geschick" value="1" min="1" max="10" onchange ="value_changed()">
in js
function value_changed(){ //pull in 3 values var staerke_value = parseint($("#staerke").val()); var weisheit_value = parseint($("#weisheit").val()); var geschick_value = parseint($("#geschick").val()); if((staerke_value + weisheit_value + geschick_value ) > 18 ){ //if out of range alert user alert("you messed up!"); } }
Comments
Post a Comment