-1

I was wondering if anyone would be able to assist with creating a button that will reset my display? I have opted to include it as a function derived from an onclick:

function setup() {
    var i;
    for (i = 0; i <= 9; i++) {
        document.getElementById(i).onclick = handleInput;
        document.getElementById("*").onclick = handleInput;
        document.getElementById("/").onclick = handleInput;
        document.getElementById(".").onclick = handleInput;
        document.getElementById("-").onclick = handleInput;
        document.getElementById("+").onclick = handleInput;

        var evaluate;
        document.getElementById("=").onclick = evaluateInput;

        var clear;
        document.getElementById("c").onclick = clearInput;
        value = "reset"
    }
}
function handleInput(e) {
    var s = document.getElementById("display").childNodes[0];
    s.nodeValue += e.srcElement.childNodes[0].nodeValue;
    console.log(e.srcElement.id);

}
function evaluateInput(e) {
    var s = document.getElementById("display");
    s.innerHTML = eval(document.getElementById("display").childNodes[0].nodeValue);

}
function clearInput() {
    document.getElementById("display").childNodes[0].selectedIndex = 0;
}

Thanks!

braX
  • 11,506
  • 5
  • 20
  • 33
owlwink
  • 91
  • 9

1 Answers1

1

We meet again...

DEMO

document.getElementById("c").onclick = clearInput;

...

function clearInput(e) {
    var s = document.getElementById("display");
    s.innerHTML = null;
}
kei
  • 20,157
  • 2
  • 35
  • 62
  • Thanks again for your help! I have finally gotten there :-) Just need to clean things up now. – owlwink Nov 19 '13 at 21:55
  • I have tried that and it is resetting the page. However is then states the following if I try to re-enter more number:Uncaught TypeError: Cannot read property 'nodeValue' of undefined. – owlwink Nov 19 '13 at 22:03
  • Under `handleInput`, you don't need `.childNodes[0]` in `var s = document.getElementById("display").childNodes[0];` – kei Nov 19 '13 at 22:11
  • When I remove the .childNores[0] in the handleInput the numbers stop appearing on my display. Any thoughts? Thanks again! – owlwink Nov 19 '13 at 22:16
  • Compare your code with the code in the demo. There must have be something that you missed. – kei Nov 19 '13 at 22:19
  • Finally got it working. Just a syntax error. Thanks again for your help. I really really appreciate it! – owlwink Nov 19 '13 at 23:17