tags:

views:

255

answers:

1

I have one simple JSP having four buttons ( Button1 , Button2 , Button3 and Button4).

The button value set into hidden field when I click on button.

I need to get the latest button click value after refresh the page ( preserve the button value).

could anyone please help me ?

<script>
    function one(tab){
        document.getElementById('h').value=tab;
    }

    function fun(){
        var value =document.getElementById('h').value;
        alert(value);
    }
</script>

<td> <input type="button" name="Tab1" id="Tab1" value="Table One" onClick="one('1')"/></td>
<td> <input type="button" name="Tab2" id="Tab2" value="Table Two" onClick="one('2')"/></td>
<td> <input type="button" name="Tab3" id="Tab3" value="Table Three"onClick="one('3')"/></td>
<td> <input type="button" name="Tab4" id="Tab4" value="Table four" onClick="fun()"/></td>

<input type="hidden" name="h" id="h"  value=""/>

+3  A: 

You might try using cookies, for example:

function one(tab){
    createCookie("savedvar",tab,1);
}

and then accessing it by: readCookie("savedvar")

Using the code from: http://www.quirksmode.org/js/cookies.html

LeaChim
Thanks for your answer. I am not accessing the cookie. My idea is to get the button value which is clicked before page refresh.
Thomman
Thanks, I implement the same logic . Working fine -
Thomman