Need help with HTML5 video 51

+1 Tom McCoy · June 28, 2014
Hi all. I am new to web design and love the tutorials Bucky offers. I have repeated tutorial 51 multiple times and it does not work for me what am I overlooking?
Here is the javascript:

function doFirst(){
    var button = document.getElementById("button")
    button.addEventListner("click", saveCrap, false);
}
function saveCrap(){
    var one = document.getElementById("one").value;
    var two = document.getElementById("two").value;
    sessionStorage.setItem(one,two);
   
    display(one);
}
function display(one){
    var rightbox = document.getElementById("rightbox");
    var two = sessionStorage.getElementById(one);
    rightbox.innerHTML = "Name of variable: "+one+"<br />Value: "+two;
}
window.addEventListener("load", doFirst, false);

and here is the html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="tom.css">
    <script src="tom.js"></script>
</head>
<body>
    <section id="leftbox">
        <form>
            <p>(key) One: <input type="text" id="one"></p>
            <p>(value) Two: <textarea id="two"></textarea></p>
            <p><input type="button" id="button" value="Save"></p>
        </form>
    </section>
    <section id="rightbox">
        Does nothing yet
    </section>
</body>
</html>

Please help.....it is driving me crazy!!

Post a Reply

Replies

Oldest  Newest  Rating
0 Erlend Haaland · June 28, 2014
Hey!

Sorry for late respond, but here is what you have done wrong:



/*Update to work! Your mistakes are noted on the right side*/

function doFirst(){
var button = document.getElementById("button"); /* Use ";" at the end. NB: Works without, but it is not recomended*/
button.addEventListener("click", saveCrap, false); /* Wrote Listener wrong*/
}
function saveCrap(){
var one = document.getElementById("one").value;
var two = document.getElementById("two").value;
sessionStorage.setItem(one,two);

display(one);
}
function display(one){
var rightbox = document.getElementById("rightbox");
var two = sessionStorage.getItem(one); /*getItem not getElementById*/
rightbox.innerHTML = "Name of variable: "+one+"
Value: "+two;
}
window.addEventListener("load", doFirst, false);


  • 1

HTML / CSS / Web Design

107,255 followers
About

Discuss, share, ask, learn and teach HTML5 and CSS3.

Links
Moderators