 <p>You can get the values with use of <code>ID</code>. But <code>ID</code> should be Unique.</p> <pre><code>&lt;body&gt; &lt;h1&gt;Adding 'a' and 'b'&lt;/h1&gt; &lt;form&gt; a: &lt;input type="number" name="a" id="a"&gt;&lt;br&gt; b: &lt;input type="number" name="b" id="b"&gt;&lt;br&gt; &lt;button onclick="add()"&gt;Add&lt;/button&gt; &lt;/form&gt; &lt;script&gt; function add() { a = $('#a').val(); b = $('#b').val(); var sum = a + b; alert(sum); } &lt;/script&gt; &lt;/body&gt; </code></pre>