Q:

JS rescue text form

I'm using this to rescue the text in the form in case the user goes to another page without submitting. But how can I clear the form when the user presses the submit button? 
function rescuefieldvalues(idarray){
    for (var i=0; i<idarray.length; i++){
        var el=document.getElementById(idarray[i])
        if (!/(text)/.test(el.type)) //skip to next element if it isn't a input type="text" or textarea element
            continue
        if (el.addBehavior && !window.sessionStorage){ //use IE behaviors to store info?
            el.style.behavior='url(#default#userData)'
            el.load("userentereddata")
        }
        var persisteddata=(window.sessionStorage)? sessionStorage[idarray[i]+'data'] : (el.addBehavior)? el.getAttribute('dataattr') : null
        if (persisteddata) //if rescued data found for this element
            el.value=persisteddata
        el.onkeyup=function(){
            if (window.sessionStorage)
                sessionStorage[this.id+'data']=this.value
            else if (this.addBehavior){
                this.setAttribute("dataattr", this.value)
                this.save("userentereddata")
            }
        } //onkeyup
    } //for loop
}

<form>
<p>Name: <input type="text"/></p>
<p>Address*: <input type="text" id="address" style="width:200px;" /></p>
<p>Feedback*:<br />
<textarea id="feedback" style="width:300px;height:150px">Your feedback here</textarea><br 
/>
<input type="submit" /></p>

</form>

<script type="text/javascript">

rescuefieldvalues(['address', 'feedback']) //rescue data 

</script>

A:

You are setting your key/value pairs with:
sessionStorage[this.id+'data']=this.value
(just a note here, I would prefer the syntax: sessionStorage.setItem(key, value)).
Similarly, you should iterate over the keys that you've stored and clear them with:
sessionStorage.removeItem(key)
If you don't have the keys that you want to clear, you might iterate over sessionStorage properties as if it was a regular object.
You can also clear all your sessionStorage with sessionStorage.clear().
Of course you have to create a function that does this and bind it to the submit event of your form.

