html - Javascript button event to trigger a form based calculation is not working -


i'm sorry few variables in dutch, change english if necessary.

this script should calculate fee of textbox "kosten". fee calculated applying percentage, made possible selecting number in combobox.

for reason, when clicking on button "totaalfooi" start calculation , result, nothing happends..

javascript code:

function berekenkosten() {      var inputkosten = document.getelementbyid('kosten');      var kosten = 0;      if (inputkosten.value != "") {          kosten = parseint(inputkosten.value);      }      return kosten;  }  var procentfooi = new array();  procentfooi["1"]=2;  procentfooi["2"]=2.5;  procentfooi["3"]=3;  procentfooi["4"]=3.5;  procentfooi["5"]=4;    function berekenfooi () {      var berekenfooi=0;      for(var = 0;          < procentfooi.length; i++) {          if(procentfooi[i].checked) {              berekenfooi=procentfooi[procentfooi[i].value];              break;          }      }      return berekenfooi;  }    function berekentotaal () {      var totaalfooi = (berekenfooi/100) * berekenkosten();      document.getelementbyid(totaalfooi).innerhtml = "totale fooi bedraagt: $" + totaalfooi;    }
<div id="jsfee">totale kosten <input type="text" id="kosten"> <br><br> graad van tevredenheid op 5      <select>          <option value="1" >1</option>          <option value="2" >2</option>          <option value="3" >3</option>          <option value="4" >4</option>          <option value="5" >5</option>      </select>      <input type="button" value="bereken" onclick="berekentotaal()">      <br><br>      <div id="totaalfooi">          </div>          </div>

change code this

function berekenkosten() {     var inputkosten = document.getelementbyid('kosten');     var kosten = 0;     if (inputkosten.value != "") {         kosten = parseint(inputkosten.value);     }     return kosten; }  function berekenfooi() {     var berekenfooi = 0,     seloption = document.queryselector('#jsfee select'),     procentfooi = [2, 2.5, 3, 3.5, 4]     return procentfooi[seloption.selectedindex]; }  function berekentotaal() {     var totaalfooi = (berekenfooi()/100) * berekenkosten();     document.getelementbyid('totaalfooi').innerhtml = "totale fooi bedraagt: $" + totaalfooi; } 

you have syntactical errors in berekentotaal function, berekenfooi function not object therefore must called () , getelementbyid requires string find element. solution don't need values in select written this

<select>     <option>1</option>     <option>2</option>     <option>3</option>     <option>4</option>     <option>5</option> </select> 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -