-1

Possible Duplicate:
jquery .click pass parameters to user function

    $('#topleft').click(function (x) {
    loadPopupBox();
    $("#popupinner").load('getdetail.php?id=' +x);
    });

How to pass a value to the variable x from an onclick event? The value of the variable x is POSTED to getdetail.php and the data returned from the getdetail.php is loaded to a DIV with ID popupinner. Now everything works except the data POST/GET.

Community
  • 1
  • 1
Sarvap Praharanayuthan
  • 4,212
  • 7
  • 47
  • 72

4 Answers4

1

Try using the .click syntax as .click( [eventData], handler(eventObject) ).

See below,

//                    v- Pass data
$('#topleft').click({x:x}, function (event) {
    loadPopupBox();
    $("#popupinner").load('getdetail.php?id=' + event.data.x); //read data from event obj
});

The [eventData] x can be accessed as event.data.x

Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
0

You can provide eventData to the click function :

$('#topleft').click({x:x}, function (e) {
    loadPopupBox();
    $("#popupinner").load('getdetail.php?id=' +e.datax);
});
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0
// say your selector and click handler looks something like this...
$("some selector").click({param1: "Hello", param2: "World"}, cool_function);

// in your function, just grab the event object and go crazy...
function cool_function(event){
    alert(event.data.param1);
    alert(event.data.param2);
}

As seen in jQuery's .click - pass parameters to user function

Community
  • 1
  • 1
Vins
  • 8,849
  • 4
  • 33
  • 53
0

What you need is click event handler. See this question to know about how it works actually.

Community
  • 1
  • 1
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53
  • this should propably be a comment instead as in "Possible duplicate of..." or similar – Nope Sep 11 '12 at 18:09