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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find ID within DIV - when ID not unique on webpage 3

Status
Not open for further replies.

friendlyposter

Programmer
Nov 1, 2002
61
US

Thanks for your consideration of this question.

I am working with IE ONLY - so I don't need a NS solution.

I want to refer to the value of a document element (span) whose ID is not unique ... BUT ... which is nonetheless unique within a certain DIV only.

The page is something like this:



<script>

function showstarter() {

alert(startTime.innerHTML) ;

var x = startTime.hh.innerText;

alert(x) ;

}

</script>



<body onload=&quot;showstarter()&quot;>

<DIV id=startTime>
<Span id=hh>01:</Span>
</DIV>

<DIV id=endTime>
<Span id=hh>01:</Span>
</DIV>

USING IE, want to refer to the hh element within a given DIV.

It would be nice if I could say...

var x = startTime.hh.innerText

Of course if it worked I would not be asking.

 
You can do something alike with forms, it might put you in the right direction.


<script>

function showstarter() {

var x = form1.hh.value;
alert(x) ;

var x = form2.hh.value;
alert(x) ;
}

</script>


<body onload=&quot;showstarter()&quot;>

<form id = &quot;form1&quot;>
<input name = &quot;hh&quot; type = &quot;text&quot; value = &quot;01&quot; size = &quot;2&quot; readonly></input>
</form>

<form id = &quot;form2&quot;>
<input name = &quot;hh&quot; type = &quot;text&quot; value = &quot;02&quot; size = &quot;2&quot; readonly></input>
</form>


vlad
 
my two cents: you should make the ID unique on the page - this is by definition what the ID is! =========================================================
if (!succeed) try();
-jeff
 

Thanks for your help everybody.

I am doing a &quot;CreateEditableClock&quot; function that builds into a webpage something like the MSWindows &quot;Adjust System Time&quot; clock popup - with + and - buttons to edit.

(The script is almost done but has a sloppy way to resolve the duplicate references - it walks thru all child tags because it knows the structure)

I was hoping for a way to do this entirely in simple DOM-navigation because ... the HTML I use for inside the many Clock DIVs is built dynamically (hence has duplicated id's --such as hh mm ss -- that repeat as a variable number of Clocks appear on a page).

Your suggestions will be useful
- I was hoping to avoid forms because of the effect I seem to get with forms juggling extra spaces and breaks into the web-page - forms is a good idea but I am very tight on web-page real estate

- I will need time to plough thru the MS site (I know, it will be good for my brain to do so) but I definitely will

- I think I am going to go for a UNIQUE id by creating my dynamic ids in a form like &quot;startTimehh&quot; and &quot;endTimehh&quot; for now

For the future, I sure would like to navigate the DOM in a way that finds unique-within-a-DIV ids. Keep scratching your heads if that helps.

By the way, your answers are very much appreciated! I am going to post my resultant script as a contribution to a cut-and-paste script website (It is a pop-up clock value editor).

Thanks for sharing.
 
unique-within-a-DIV ids

maybe something like:
[tt]<div id=&quot;div1&quot;>
<div id=&quot;div1_div1&quot;></div>
<div id=&quot;div1_div2&quot;></div>
<div id=&quot;div1_div3&quot;></div>
</div>

<div id=&quot;div2&quot;>
<div id=&quot;div2_div1&quot;></div>
<div id=&quot;div2_div2&quot;></div>
<div id=&quot;div2_div3&quot;></div>
</div>
[/tt] =========================================================
if (!succeed) try();
-jeff
 
Have you tried adding the parents id to the children?

Something like

<div id=&quot;1&quot;
<div id=&quot;1_1&quot;
<div id=&quot;1_2&quot;

<div id=&quot;2&quot;
<div id=&quot;2_1&quot;

You could refer to them collectively using loops or individually as always. Or does that mess things up?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top