I am learning coffeescript, and I am wanting to make an script that multiplies the number I put in by PI. The issue is in how to get the HTML5 input to the coffeescript code (actually, in the HTML file it is now javascript).
Coffeescript before compiling:
x = y * Math.PI;
alert(x);
HTML5:
<html>
<head><title>Coffeescript Test</title></head>
<body>
<form action="" method="GET">
<input type="text" name="input" value="NUMBER">
<input type="button" name="Solve" value="Equals" onClick="Coffee()">
<span id="result" />
</form>
<div id="Coffeescript">
<script type="text/javascript">
(function Coffee() {
var x;
x = y * Math.PI;
alert(x);
}).call(this);
</script>
</div>
</body>
</html>
The variable "y" is supposed to be the input. How do I get a number from the HTML input box to the new javascript code? If possible, give me coffeescript code instead of javascript.
New code after using Paul D. Waite answer (This code works well):
<html>
<head><title>Coffeescript Test</title></head>
<body>
<div id="Coffeescript">
<script type="text/javascript">
function coffee() {
var x;
x = document.querySelectorAll('input[name="pi_input"]')[0].value * Math.PI;
alert(x);
}
</script>
</div>
<form action="" method="GET">
<input type="text" name="pi_input" value="NUMBER">
<input type="button" name="Solve" value="Solve" onClick="coffee()">
<span id="result"/>
</form>
</body>
</html>