Reputation: 2944
var value;
$("#Grid1").click(function(e) {
var row = jQuery(e.target).parent();
value= row.attr("id");
});
var onrowclick = function() {
("#Grid1").click($("#showgrid").load('/Names/Friends/satish/' + value));
};
I am trying to send the value on URL.
When I am giving like this I am not getting the output result. Am I doing this correctly?
Is the problem that I am handling click event on same grid two times?
Upvotes: 0
Views: 6761
Reputation: 31173
UPDATED: in responce to your comment:
if you want assign a variable outside the click event you can do this:
$(function () {
// declare the variable.. this one will hold the parent id
var my_value;
// now the click event...
$("#Grid1").click(function(e) {
e.preventDefault();
// my_value now is setted outside...
my_value = $(this).parent().attr("id");
});
// now for the example we observe the click event you can use it in other way!
$('#Grid1').bind( 'click' , function() {
// now as you can see we are using my_value that come from outside!
$('#showgrid').load('/Names/Friends/satish/' + my_value );
});
});
ADDITIONAL NOTE
now i don't know if the #Grid1
is inside the #showgrid
but if this is the case, you need to use the live()
method!
like this:
$("#Grid1").live( 'click' , function(e) {
// do something here as above...!
});
assuming:
<div id="this_is_parent_of_Grid1">
<a id="Grid1" href="">click</a>
</div>
OR if you use table
<table><tr>
<td id="this_is_parent_of_Grid1"><a id="Grid1">click</a></td>
</tr></table>
Upvotes: 1
Reputation: 322622
Hard to say without seeing HTML, but I think you're trying to do something like this:
// Initialize variables outside of the handler
var row;
var value;
$("#Grid1").click(function(e) {
// Assign values to variables when event handler fires
row = jQuery(e.target).closest('tr');
value= row.attr("id");
$("#showgrid").load('/Names/Friends/satish/' + value);
});
// Now you can access the local variables
function someFunction() {
alert(value);
alert(row.get(0));
}
I changed parent()
to closest()
since I don't know your HTML structure.
EDIT:
For clarity, I am assuming that #Grid1
is some sort of container (table
perhaps), and you are clicking on something in the content of a tr
. And #showgrid
is a separate component external to the container that displays additional info.
EDIT:
I'll assume from your comment that you need to access the row element and/or ID from outside the handler. I've updated the example to reflect how this can be done. Let me know if that's not what you meant.
Upvotes: 2
Reputation: 10081
Why not use the following?
$("#Grid1").click(function(e) {
var value= $(e.target).parent().attr("id");
$("#Grid1").load('/Names/Friends/satish/' + value);
});
};
This code is still fragile, but probably does more of what you want.
Upvotes: 0
Reputation: 4288
what do you need to do?
var value;
$("#rowid").click(function() {
value = $(this).value();
});
or you can try something like this:
var value;
$("#rowid").click(function() {
value = $(this).value();
$("#showgrid").html( $.load("/Names/Friends/Satish/" + value) );
});
Upvotes: 0