开发者

parentNode in Javascript doesn't seem to work for me

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:Tex开发者_开发百科tBox>
  </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...


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.


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


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

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

regards,
Stijn

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜