how to get the value of a function from a button click in javascript? -
i new javascript , trying go through tutorials understand concepts.
this function
function tocelsius(fahrenheit){ (5/9) * (fahrenheit-32); document.getelementbyid("demotemp").onclick.tostring(); }
and trying invoke here:
<form> <br> enter number: <input type="text" name="firstname"> <!-- <input type="text" name="lastname"> --> <button type="button" onclick="tocelsius()"> new temp in celsius </button> </form> <p id="demotemp"></p>
i want user able enter value , hit button tell them new temperature fahrenheit celsius
just put result in inner html.
function tocelsius(){ var fahrenheit = document.getelementsbyname("firstname")[0].value; var cel = (5 / 9) * (fahrenheit - 32); document.getelementbyid("demotemp").innerhtml = cel; }
Comments
Post a Comment