Jump to content

cech

Recommended Posts

pls i have been trying to design a page for calculating circumference of circle with the following code but after inputting all the code both in html and javascript as shown below , onclicking submit calculate circumference it never response. can someone help me check if there is anything wrong with the code?

 

html code

<script src="find.js"></script></head><body> <h1>Circumference calculator</h1> <p>Enter the length of radius: <input type="text" id="txtRadius" /></p> <p><input type="button" id="btnSubmit" value="calculate circumference" onclick= "init();" /></p> <p id="result"></p> </body> </html>

 

here

javascript code:

function init(){var mybotton = document.getElementById("btnsubmit");mybotton.onclick = processAnswer;}/************************************************************************/onload = init;/************************************************************************/function processAnswer(){var inputB0x = document.getElementById("txtRadius");var radius = parseInt(inputB0x.value);var result = document.getElementById("result");var resultString = "";if (isNaN(radius) ){alert ("please, enter a number");}else{var circ = getCircumference(radius);resultString = "Circumference is: " + circ;result.innerHTML = resultString;}}/***********************************************************/function getCircumference(rad){var circumference 2 * (Math.PI * rad);return circumference;}

Link to comment
Share on other sites

One problem is that you selected document.getElementById("btnsubmit"); but your element's ID is btnSubmit.

 

You shouldn't be calling init() when the button is clicked, either. That should only be called when the window loads. So remove onclick= "init();" from the button.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...