all groups > dotnet jscript > january 2007 >
You're in the

dotnet jscript

group:

Get Row Line Number in JavaScript


Get Row Line Number in JavaScript mianiro
1/17/2007 5:11:37 AM
dotnet jscript:
Hello -

I am using JavaScript with an ASP.Net project. I have a textbox
control inside of a grid. I would like to know the row number that the
textbox control is contained in. I am trying to loop through and
determine the row number by looking for the "TR" tagName. However,
while I am looping through this, the tagName goes from DIV to Form to
Body to HTML ... never hits any table elements. Any thoughts? Am I
doing this correrectly?
function lostFocus(maskControl, detlines)
{
if (detlines == "N") maskControl.style.backgroundColor = "#ffffff";
else{
var e = maskControl;
var b = "FALSE";
do
{
if (e.parentNode.tagName=="TR"){
b = "TRUE";
e = e.parentelement;
if ((2 % 2) == 0) maskControl.style.backgroundColor =
"#F7F6F3";
else maskControl.style.backgroundColor = "#ffffff";
}
else e = e.parentNode;
}
while (b == "FALSE");
}
}


If you are wondering what i am doing ... I have a gridview with
alternating row colors. When you select a textbox in the grid, the
textbox turns green. I need to set the textbox back to the original
color when the textbox loses focus. Well since the textbox is always
green, I need to determine the correct color by counting the rows. If
that makes sense.
Thank you!!!
Re: Get Row Line Number in JavaScript Brian Williams
1/17/2007 12:58:47 PM
Not sure if your code will work but I notice a typeo, try changing e =
e.parentelement; to e = e.parentElement;

Regards,
Brian K. Williams



[quoted text, click to view]

AddThis Social Bookmark Button