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

Dynamic ID's 2

Status
Not open for further replies.

elements

Programmer
Oct 15, 2002
2
CA
Hi,

Quick summary before I pose my question. I have windows media player embedded (hidden) and use images to control the player (play buttons, stop buttons, etc). I show a list of sentences generated dynamically through a database. Beside each sentence is a play and stop button that will connect the correct audio to the embedded windows player.
Along with these buttons, I have span tags that have unique id's (corresponding to the record count of a database.) For example:

1)buttons here<span id=&quot;Msg1&quot; style=&quot;color:green&quot;></span>
2)buttons here<span id=&quot;Msg2&quot; style=&quot;color:green&quot;></span>
3)buttons here<span id=&quot;Msg3&quot; style=&quot;color:green&quot;></span>
etc...

I use this script to display a message in the specific span tag I am targeting:

<SCRIPT FOR=&quot;MediaPlayer&quot; EVENT=&quot;buffering(Start)&quot;>
Msg.innerText = &quot; Buffering...&quot;
</SCRIPT>

But ofcourse the id in the above script is not correct. Now I am able to grab the number I want but I still cannot refer to the correct ID. For example:

<SCRIPT FOR=&quot;MediaPlayer&quot; EVENT=&quot;buffering(Start)&quot;>
newMsg = &quot;Msg&quot;+newNumber //newNumber is the number
//I am able to get
newMsg.innerText = &quot; Buffering...&quot;
</SCRIPT>

So my question is: How can I refer to an id that is generated dynamically? The span tag id will always be &quot;Msg&quot; plus some number. My attempt is pretty lame but I am not sure how to go about this. Maybe naming the variable dynamically is not the correct approach. Any ideas would be greatly appreciated.

PS. I need all these span tags so I can't use the solution of just having one.

Thanks
 
Try this:

newMsg = eval(&quot;Msg&quot; + newNumber)

Hope this helps,
Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Awesome Erik, it worked perfectly!

Thank you,
Trace
 
I'm glad I was able to help.

By the way: I'm interested in the complete code. Do you mind to send me a copy ??

real_diruk@hotmail.com

Erik <-- My sport: Boomerang throwing !!
!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top