GetElementbyID question - within MasterPage/contentpage - within tables

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

I've inherited a project that has quite a few Table rows - inside each cell,
within the row are a couple of textboxes ("in" and "out"), along with a
"total" label.

Also - this is all within a Content Page/Master Page scenario - I've got the
function inside the Content page, along with the all the items herein

On each row, each of the in and out and total controls have a number
associated with them, like:

In1, Out1, total1
In2,Out2, total2, etc

For each Out textbox, I'm adding the onblur attribute to run this function

I'm trying to create ONE javascript function to add the in and out
textboxes, based the number of the row, which will add the two textbox
values, and put it in the label for that row, but I keep getting errors and
I'm not sure what to do....

I've got a function started but it keeps getting errors, and I'll admit I'm
not a pro with JS. Here's what I've got so far:


function getmiles(num) {
start=document.getElementById("In" + num).getAtribute("value"); // < -
can't find
end=document.getElementById("Out" + num).getAtribute("value");
document.getElementById("Total" + num).getAtribute("value")=start-end;
}
'num' is getting populated, for sure. The main error is
'document.getElementById("..") is null or not an object, plus a couple of
"object expected" errors....

it happens any time I use the structure above (document.getElementById("In"
+ num).getAtribute("value"))

can someone help me here?
 
Controls in content pages have combined id. You can see them if you view the
html source of the page when it is displayed in your browser.

This javascript function can assist you in finding controls by the tag name
and partial control id:

function findControl(tagName, controlId)
{
var aControls = document.getElementsByTagName(tagName);
if (aControls==null)
return null;
for (var i=0; i< aControls.length; i++)
{
var j = aControls.id.lastIndexOf(controlId);
if ((j > -1) && (j == (aControls.id.length - controlId.length)))
return aControls;
}
return null;
}


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Back
Top