0

as I wanted to improve myself , I decided to create a calculation tool for my table top games. I've created an html form and a small script but when I'm clicking on the submit button... Nothing Happens. I've tried PHP instead of Javascript the result was exactly the same. So I wish , you could give me some advice and help me understand why it wasn't working.

<!DOCTYPE html>
<html>
<head>
 <title>The Kiki Meter</title>
 <link rel="stylesheet" type="text/css" href="apperence.css">
</head>
<body>
 <h1>The Kiki Meter</h1>
 <div>
 <form name="Calculator">
 Attack Dice Roll : <input type="text" name="Attack_Dice">
 Defense Dice Roll : <input type="text" name="Defense_Dice">
 IP : <input type="text" name="IP">
    Strengh: <input type="text" name="Strengh">
 Weapon Dmg : <input type="text" name="Weapon_Dmg">
 <input type="submit" value="Calculer">
 </div>
 <script type="text/javascript">
  var Attack = document.getElementsByName("Attack_Dice");
  var Defense = document.getElementsByName("Defense_Dice");
  var IP = document.getElementsByName("IP");
  var Force = document.getElementsByName("Strengh");
  var Weapon_Dmg = document.getElementsByName("Weapon_Dmg");
  var Success=(Attack-Defense-IP)/100;
  document.write(Success);
  if (Success<0) {
   document.write(Success/(-2));
  }
  else {
   document.write((Force + Weapon_Dmg)*Success); 
  }
 </script>
</body>
</html>
Gholgot
  • 1
  • 1
  • Start here: http://stackoverflow.com/questions/10693845/what-do-queryselectorall-getelementsbyclassname-and-other-getelementsby-method Then look for how you get the value of an input. Note that the value is always a string, so you'll need to know how to convert that to a number. Don't use `document.write`, after the initial parsing of the page when you do that it does a `document.open`, which wipes out the page. So look for how you add information to the document via the DOM (or a library like jQuery that uses the DOM). – T.J. Crowder Dec 04 '16 at 17:56
  • You'll also want an event handler, so that's another thing to look up; you probably want to do this calculation in response to a user event, like clicking a button. – T.J. Crowder Dec 04 '16 at 17:58
  • Thanks for this fast answer and giving me a direction where to start at ! – Gholgot Dec 04 '16 at 19:02

0 Answers0