Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

html - How to get value from checkbox checked using javascript?

Why my javascript code didn't work? This output value is NaN.

for example my checkbox html code like this

<input type="checkbox" name="gejala" class="form-check-input checkbox-1x" id="GJ01" value="1"> 
<input type="checkbox" name="gejala" class="form-check-input checkbox-1x" id="GJ02" value="1">
<input type="checkbox" name="gejala" class="form-check-input checkbox-1x" id="GJ03" value="1">
<h5 id="probabilitas"></h5>

and want show this total value probability with js code like on my comment like this :

//----my array RULE--//
let AI = ["GJ01","GJ02","GJ03"];
for (var checkbox of markedCheckbox) {
    if(checkbox.checked){
      if(AI.includes(checkbox.id)){
        console.log("Flu Burung");
        document.getElementById("kesimpulan").hidden=false;
        document.getElementById("PE01").hidden=false;    
        document.getElementById("Solusi01").hidden=false; 

        //myBugs code
        for (var checkbox of markedCheckbox){
          if(AI.includes(checkbox.value)){
            y+=parseInt(checkbox.value);
          }
        }
        probabilitas = document.getElementById("probabilitas");
        probabilitas.innerHTML = (probabilitas.innerHTML.slice(0, -1) + y / 10 ) * 100;
      } else if {
    }
  }
}
question from:https://stackoverflow.com/questions/65859947/how-to-get-value-from-checkbox-checked-using-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
parseFloat(probabilitas.innerHTML.slice(0, -1))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...