0

Can't display result. Need help please.

<!DOCTYPE html> <html> <head> <title>Convert Meters to Kilometers</title> <meta charset="utf-8" /> <!-- conversion.html - webpage showing my skill with innerHTML Thomas E. Weber - thomas.weber@my.southcentral.edu Written:09/20/2016 Revision: --> <script> function getInput() { var getMeter = ""; var result; getMeter = document.getElementById("txtMeter").value; getMeter = parseInt(getMeter); result = calculate(getMeter); showResult(result); } function calculate(meter) { meter = parseInt(meter) * 1000 return meter; } function showResult(rslt) { placeholder = document.getElementById("message"); placeholder.innerHTML = "Your conversion result is: " + rslt; } </script> <style> body { font-family: optima, helvetica, arial, sans-serif; } h1 { color: #000080; /* drak blue RRGGBB */ border: 1px solid #000080; background: #CECECE; /* light gray */ padding: 10px; /* space between text and border */ text-align: center; font-family: helvetica, arial, sans-serif; margin: 20px 0px; /* space between border and the other objects */ } </style> </head> <body> <h1>Convert Meters to Kilometers</h1> <form id="frmUserInput"> Meters: <input type="text" name="txtMeter" id="txtMeter" value=1 onblur="showResult()" /><br /><br /> <button type="button" name="btnMeter" onClick="showResult()">What is your number in Kilometers?</button><br /><br /> </form> <script> getInput(); </script> <span id="message"></span> </body> </html>

23rd Sep 2016, 5:40 PM
Thomas Weber
Thomas Weber - avatar
3 Réponses
0
<!DOCTYPE html> <html> <head> <title>Convert Meters to Kilometers</title> <meta charset="utf-8" /> <!-- conversion.html - webpage showing my skill with innerHTML Thomas E. Weber - thomas.weber@my.southcentral.edu Written:09/20/2016 Revision: --> <script> function getInput() { var getMeter = ""; var result; getMeter = document.getElementById("txtMeter").value; getMeter = parseInt(getMeter); result = calculate(getMeter); showResult(result); } function calculate(meter) { meter = parseInt(meter) * 1000 return meter; } function showResult(rslt) { var placeholder = document.getElementById("message"); placeholder.innerHTML = "Your conversion result is: " + rslt; } </script> <style> body { font-family: optima, helvetica, arial, sans-serif; } h1 { color: #000080; /* drak blue RRGGBB */ border: 1px solid #000080; background: #CECECE; /* light gray */ padding: 10px; /* space between text and border */ text-align: center; font-family: helvetica, arial, sans-serif; margin: 20px 0px; /* space between border and the other objects */ } </style> </head> <body> <h1>Convert Meters to Kilometers</h1> <form id="frmUserInput"> Meters: <input type="text" name="txtMeter" id="txtMeter" value=1 onblur="showResult()" /><br /><br /> <button type="button" name="btnMeter" onClick="getInput()">What is your number in Kilometers?</button><br /><br /> </form> <span id="message"></span> </body> </html>
23rd Sep 2016, 5:58 PM
Catlin
Catlin - avatar
0
You had to change the method call on button click to getInput() and delete the script call in the bottom of the form.
23rd Sep 2016, 5:59 PM
Catlin
Catlin - avatar
0
Thank you
23rd Sep 2016, 6:20 PM
Thomas Weber
Thomas Weber - avatar