I want a blank field, not "undefined"

When I clear the memory of HTML5 WebStorage (or local storage), then open the page again to look at the fields, they are filled with “undefined.” I’d like them to be blank. How do I do that?

Here is the code used for loading the memory back into the fields at the click of a button. Instead of a blank field for each textarea, “undefined” is in each field:

            function loadData()
                //front suspension
                    document.form1["s1frontTowerMtgShock3"].value = localStorage["practicelog.html.s1frontTowerMtgShock3"];
                    document.form1["s1frontTowerMtgShock2"].value = localStorage["practicelog.html.s1frontTowerMtgShock2"];
                    document.form1["s1frontTowerMtgShock1"].value = localStorage["practicelog.html.s1frontTowerMtgShock1"];
                    document.form1["s1frontTowerShockMtgOther"].value = localStorage["practicelog.html.s1frontTowerShockMtgOther"];
                    document.form1["note3"].value = localStorage["note3"];

Here is the code for deleting the memory:

            function clearData()
                //if (html5StorageSupported())
                    // Clear data from local storage
                    document.form1["s1frontTowerMtgShock3"].value = "";
                    document.form1["s1frontTowerMtgShock2"].value = "";
                    document.form1["s1frontTowerMtgShock1"].value = "";
                    document.form1["s1frontTowerShockMtgOther"].value = "";
                    document.form1["Note3"].value = "";

                    document.form1.numStored.value = determineNumberStoredElements();
               // }

Somehow I need to check for a null field and set it to “” instead of the default “undefined”. How do I do that?


Try something like this in loadData() for each field:

document.form1["s1frontTowerMtgShock3"].value = localStorage["practicelog.html.s1frontTowerMtgShock3"].length>0 ? localStorage["practicelog.html.s1frontTowerMtgShock3"] : '';

No, that did not work. Why did you use .length>0?

I used .length>0 to test the value to have at least one character. But instead of this property, try to test if its undefined, != null or != undefined .