Javascript calculator not working. -
i created javascript calculator little while ago. worked me ages, after going have discovered simple doesn't work @ anymore.
here js fiddle... http://jsfiddle.net/adammartin121/xxfxv/
this code used. it's long , unnecessary. know firstly why it's not working, , secondly more efficient way of doing this?
javascript code... var display = document.getelementbyid("display"); document.addeventlistener("domcontentloaded", init, false); function init() { var name = prompt("enter name", ""); if (name == null) { document.getelementbyid("head").innerhtml="enter name!"; } else { document.getelementbyid("head").innerhtml= "<p>welcome, " +name+ ". </p> <p2> simple javascript calculator. open source , designed people learn javascript. <br> feel free copy , paste code, , use how wish. </p>"; } document.getelementbyid("calc").display.style.block; } function naught() { var display= document.getelementbyid("display"); display.value+="0"; } function one() { var display= document.getelementbyid("display"); display.value+="1" } function two() { var display= document.getelementbyid("display"); display.value+= "2"; } function three() { var display= document.getelementbyid("display"); display.value+="3"; } function four() { var display= document.getelementbyid("display"); display.value+="4"; } function five() { var display= document.getelementbyid("display"); display.value+="5"; } function six() { var display= document.getelementbyid("display"); display.value+="6"; } function seven() { var display= document.getelementbyid("display"); display.value+="7"; } function eight() { var display= document.getelementbyid("display"); display.value+="8"; } function nine() { var display= document.getelementbyid("display"); display.value+="9"; } function add() { var display= document.getelementbyid("display"); display.value+="+"; } function take() { var display= document.getelementbyid("display"); display.value+="-"; } function times() { var display= document.getelementbyid("display"); display.value+="*"; } function divi() { var display= document.getelementbyid("display"); display.value+="/"; } function equal() { var display= document.getelementbyid("display"); display.value= eval(display.value); }
thanks in advance.
this line:
document.getelementbyid("calc").display.style.block;
should (style comes before display):
document.getelementbyid("calc").style.display.block;
also, you're selecting in javascript id calc
, in html table, you've given class calc (<table class="calc">
) instead, change id (<table id="calc">
) , voila.
Comments
Post a Comment