function - How can I stop an alert in javascript from firing when the page loads, and make it run when a button is clicked? -


without using jquery, how can javascript alert fire @ right time? it's firing when page loads. created temp converter , "convert fahr" button , "convert cels" button fire off converted temps in pop "alert". both buttons executing respective temp conversion math functions i'd add alerts when buttons clicked.

document.getelementbyid('convert').onclick = maketempf(); document.getelementbyid('convertc').onclick = maketempc();  function maketempf() {     var d, b, c;     var f = document.getelementbyid('f').value;     b = f - 32;     c = b * 5;     d = parseint(c / 9);     alert('celsius temperature ' +d);     // console.log(d); }   function maketempc() {     var g, b, d;     var c = document.getelementbyid('c').value;     b = c * 9;     d = b / 5;     g = parseint(d +32);     alert('fahrenheit temperature ' +g);     // console.log(g); } 

assign callbacks, not invocation returns.

document.getelementbyid('convert').onclick = maketempf; document.getelementbyid('convertc').onclick = maketempc; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -