views:

94

answers:

3

Dear All,

I need to get the Last Click arguments.

My Javascript

 <a href="#" onclick="show(fid1,1);">Link1</a>
 <a href="#" onclick="show(fid2,2);">Link2</a>
 <a href="#" onclick="show(fid3,2);">Link3</a>

Now I Need Another javascript Function that finds out the last click of show function's arguments. How to do it any idea?

function LastclickId(){
    //code
}
+1  A: 

set a global variable in the show function

then read it in the lastClickID function

Cato Johnston
+4  A: 

If I understand your question correctly, you want to keep track of the most-recent arguments to show(), right? If that's indeed what you want to do, you could add two variables to your global namespace and just assign the values whenever you call show():

last_foo = 0; // Global namespace
last_bar = 0;

function show(foo, bar) {
    last_foo = foo;
    last_bar = bar;

    ...
}

Then in any function on that page, you can get the values from last_foo and last_bar.

Tyson
A: 

If you don't like to have global variables around, you can wrap your related methods into a single object:

var yourObject = function () {

  // private members...
  var lastClicked;

  function setLastClicked(id, n) {
    lastClicked = id + "," + n
  }

  return {

      // public members...
      show: function (foo, bar) {
          // ....
          setLastClicked(foo, bar);
      },

      getLastClicked: function(){
          alert(lastClicked);
      },
};

}();

CMS