I am using javascript
and html
to do a form. How do I code such that I can have an equation in each option value? I am trying to achieve something like this(shown below) but the code below does not work.Can anyone be able to help? Thanks.
Length x Width = X
The equation in the option value doesn't work
Length(ft): <input type="text" id="Length"><br>
Width(ft): <input type="text" id="Width"><br>
<form>
<select id="grassheight">
<option value="2x+2.5">10mm</option>
<option value="2x+3.5">20mm</option>
<option value="2x+4.5">30mm</option>
</select>
</form>
<button onclick="myFunction()">Calculate</button><br>
<script>
function myFunction() {
var grassheight = document.getElementById("grassheight").value;
var Length = document.getElementById("Length").value;
var Width = document.getElementById("Width").value;
var area = Math.ceil(Length * Width / 0.92 * grassheight);
document.getElementById("Result").innerHTML = area;
}