1

It would be little complicated. Suppose I have a select list with items as status.I select a status and do some modification in the page, when I change to different status all the modificatiions which I did for previous selected status should be saved and send to a servlet. I was trying to do using change() , but it was taking current select field. and Also page relaods when status from the select is is changed thats y all the previous selected fields value also get lost.

Do anyone have ides of how to do it using jquery/Javascript as if I get the value I can pass to the servlet.

Basically I work on component based java using Apache Click framework. If some can relate with that too it would be great help too.

frictionlesspulley
  • 11,070
  • 14
  • 66
  • 115
user695362
  • 11
  • 1
  • 4

2 Answers2

2

basically you need to store the previous value yourself and keep track of it, something like that:

var $selectElement = $("#selectElement");

$selectElement.change(function () {
    var previousValue = $selectElement.data("previous");

    //do something with previous value

    $selectElement.data("previous",
        $selectElement.find("option:selected").val);
}).change();

a quick example http://jsfiddle.net/dCkwd/

Kris Ivanov
  • 10,476
  • 1
  • 24
  • 35
  • how I am thinking is declaring a global variable , and storing the current value in globals and then passing on the servlet on change will this works. also Suppose user selects the status and then type some thing on text box, check some checboxes then I am storing these values in onchange for checkbox and onblur for textbox.Is this approach fine. – user695362 Oct 31 '11 at 16:52
  • I am not familiar with the `click-framework` so I can't advise you on how to do it with global variables passed on the servlet, All I am providing you is way to track previous value using jQuery on the client, you can implement whatever you want when the change happens – Kris Ivanov Oct 31 '11 at 17:35
0

Try storing the values in a cookie with the jQuery $.cookie plugin and updating the cookie on change(). You can then access the latest cookie value.

I hope this helps!

dSquared
  • 9,725
  • 5
  • 38
  • 54