Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DOM to find input name 1

Status
Not open for further replies.

MDA

Technical User
Jan 16, 2001
243
US
I have a spreadsheet engine the dynamically renders html. I need to find a way to pinpoint an input box based on the alt of an img to the right of the input. So in the example below, I want to be able to specify CELLB5 and get returned IB5. However, the one strange twist is that there may be an instance in which CELLB5 appears more than once, so somehow I have to return all input names with the alt set to CELLB5.

Is this possible? If so what is the best approach?

Example:
<input size=8 onblur=foc(this) name=IB5 CLASS=input>&nbsp;<img src="/images/info.gif" alt="CELLB5">

Thanks in advance for your feedback.
MDA
 
Can you give the image a name? That would make it significantly easier.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Well currently I only can change the alt text of the image, which is an instruction line in the spreadsheet. The engine will render the image next to the textbox if the alt field is used. But there is no way to add a name field at this time.

However, let’s say that it is possible to add a name to the image, where would I go from there? What if it is not possible to add the name? Dead end?

Thanks,

Mike
 
What we need is access to the image. Without the name, then we would have to loop through the document.images[] array and check the alt of each one. Lets say there is a function getImages(string) which returns an array of image objects represented by the string. This can be filled in later.

Code:
function getTextBoxes(img_param)
{
  var imgs = getImages(img_param);
  var txts = new Array();

  for (var i=0;i<imgs.length;i++)
  {
    var temp = imgs[i].previousSibling;
    while (temp.tagName.toUpperCase() != "INPUT")
    {
      if (!temp.previousSibling)
      {
        temp = null;
        break;
      }
      temp = temp.previousSibling;
    }
    txts[i] = temp;
  }
  return txts;
}

This code takes a name and stores all the images associated with that name in an array called imgs. It then declares a variable called txts to be an array. It loops through the imgs array, and for each element, continues going back through its nodes until it reaches one of type "input" or there are no more. It then stores the input into txts and goes on to the next one. At the end, txts is returned.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top