i have a textbox inside td
i want textbox to fire td.click function on focus so that i can get row n column number to get its text and send to web method
but user wont click td so can i achieve this??
$('td').click(function(){
var col = $(this).parent().children().index($(this));
var row = $(this).parent().parent().children().index($(this).parent());
alert('Row: ' + row + ', Column: ' + col);
});
mark up
<table>
<tr><td>e1</td>e2<td>e3</td></tr>
<tr><td>e1</td>e2<td>e3</td></tr>
<tr><td>e1</td>e2<td>Textbox</td></tr>
</table>
There is an element.trigger method, that you could use to do it.
The other problem is to get a textbox a focus event fires. TD doesn’t have a focus state but in some browsers you can emulate it by setting an tabindex attribute. Maybe it’s better to use form elements (input) so it can be focused by default.
But you will get another problem when it will be clicked than event will be fired two times – on your click and on focus the element. You can play with event bubbling, but i think better way is to set it only on focus.