views:

211

answers:

3

I use a textbox inside a gridview and its onkeyup function doesn't seem to work....

Here is my gridview

<asp:TemplateField>
  <HeaderStyle Width="12%" />
  <HeaderTemplate>
   Advance Detucted
   </HeaderTemplate>
   <ItemTemplate>
    <asp:TextBox ID="TxtAdvanceDeducted" runat="server"  
CssClass="text_box_height_14_width_50" onkeyup="check('this');"></asp:TextBox>
  </ItemTemplate>
   <ItemStyle Width="12%" HorizontalAlign="Center"  />
   </asp:TemplateField>

And my javascript function,

var table = el.parentNode.parentNode.parentNode;
for (var y = 0; y < table.rows.length; y++) 
{
    for (var x = 0; x < table.rows[y].cells.length; x++) 
     {
        if (table.rows[y].cells[x] == el) 
        {
            alert("Row:" + y + " Cell: " + x);
        }
    }
}

When inspected through webdeveloper toolbar i got the error,

el.parentNode is undefined

Any suggestion...

alert(table.rows.length) gave me 3... But i have 2 rows + one header row...

+2  A: 

Replace

onkeyup="check('this');" // you are passing a string 'this' to the function.

with

onkeyup="check(this);" // you are passing a reference of the element.
rahul
@rahul it worked but i cant receive alert...
Pandiya Chendur
add some alerts inside the first and second for-loop as well to check
TheStijn
A: 

is this being passed as a string rather than an object perhaps is should be:

onkeyup="check(this)

This might be down to asp syntax though. A good way to test is alert or use console.log in firebug to find out what is being passed to the function e.g.

console.log(el);

or

alert(el);

as the first line of the function

matpol
A: 

hi,

I'm not familiar with ASP: are the quotes around this required?

check('this') => check(this)

regards,
Stijn

TheStijn
@TheStijin see my edited question
Pandiya Chendur