How do I change a variable based on the users option from a drop down menu in html/javascript -


i have researched , have been trying figure problem out few days. haven't found helps other make more complex. i'm trying change variable health, based on level character can choose drop down menu. can't figure out how javascript function , call answer have in drop down menu. appreciated! here's code:

<!doctype html> <html> <head>league of legends damage calculator<title> </title> </head> <body>  <p> <script> var health; var ad; var adspeed; var movespeed; var healthregen; var armor; var apresist; </script> </p>  <p> aatrox base stats: <br> <img src="http://ddragon.leagueoflegends.com/cdn/4.5.4/img/champion/aatrox.png"     width="150" height="150"> <br> <script> document.write("health - " + health); </script> basic attack damage - 55  basic attack speed - .651  movement speed - 345  health regen - 5.75  armor - 18  magic resist - 40  </p> <p> <form name="form1">     <select id="opts" onchange="showform()">         <option value="0">level stats - 1</option>         <option value="1">level stats - 2</option>         <option value="2">level stats - 3</option>         <option value="3">level stats - 4</option>         <option value="4">level stats - 5</option>         <option value="5">level stats - 6</option>         <option value="6">level stats - 7</option>         <option value="7">level stats - 8</option>         <option value="8">level stats - 9</option>         <option value="9">level stats - 10</option>         <option value="10">level stats - 11</option>         <option value="11">level stats - 12</option>         <option value="12">level stats - 13</option>         <option value="13">level stats - 14</option>         <option value="14">level stats - 15</option>         <option value="15">level stats - 16</option>         <option value="16">level stats - 17</option>         <option value="17">level stats - 18</option>     </select> </form>  <script> function stats(form1) {     var decidelevel;     decidelevel = document.getelementbyid('opts'); if(decidelevel = "0"){     health = 395; }; if(decidelevel = "1") {     health = 395 + (85 * decidelevel); }; // etc }; </script> </p>  </body> </html> 

you've got couple problems: first, <select> calling showform() when changes, don't see function named showform in javascript. should change stats(). then, you're doing decidelevel=document.getelementbyid('opts');, need go step further: decidedlevel=document.getelementbyid('opts').value; it.

edit:

an easier way write if statements using switch:

switch(decidedlevel){     case 0:         //do stuff     break;     case 1:         //do other stuff     break;     //etc     default:         //if none match, happens     break; } 

edit2: ps:

you doing if statement's incorrectly - if (var=1) assign var 1. instead, use if (var==1) true/false.

cheers!


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -