0

They only taught us how to inline script in school so I was looking on the internet. I found something but it doesn't work.
The code I have right now : DEMO FIDDLE

<title>DPS</title>
<body>
    <form id="value-input">
        <input type="text" name="damage" id="damage" placeholder="Damage">
        <input type="text" name="firerate" id="firerate" placeholder="Firerate">
        <input type="button" id="submit" value="Calculate">
        <input type="reset">
    </form>
    <script src="main.js"></script>
</body>


function calc() {
   var damage = document.getElementById('damage');
   var firerate = document.getElementById('firerate');
   alert(newFirerate * newDamage);
}

document.querySelector('submit').addEventListener('onClick', calc);

It's really basic and it's just to learn how to develop Chrome apps, without using inline scripts.

Varun Nath
  • 5,570
  • 3
  • 23
  • 39

1 Answers1

1

There are a few errors here as I can see it.

First off, you're not currently getting the values from the inputs, only getting the inputs themselves. Do this instead:

var damage = document.getElementId('damage').value;
var firerate = document.getElementById('firerate').value;

Next up, in your alert you're using variables "newFirerate" and "newDamage" which you have not defined anywhere. I assume you want to use the ones you have defined:

alert(firerate * damage);

And lastly, in your event listener, change 'onClick' to 'click'.

EDIT: Also change the query selector when adding the event listener from 'submit' to '#submit'.

Chipowski
  • 116
  • 7
  • Thanks. I fixed all these errors, but it still does not work. Not in the browser nor in the packaged app. – Jan Müller Jul 31 '14 at 11:53
  • Oh I completely forgot.. editing answer. There was one more thing. When adding an event listener (and in many other cases) you have to specify in the selector whether it's an ID or a class, by adding a '#' or '.' in the beginning of the selector string. – Chipowski Jul 31 '14 at 12:01