Here's what I need to do: |
Here's what I need to do: |
INSTANT |
Oct 9 2007, 06:38 AM
Post
#1
|
Group: Members Posts: 3 Joined: 9-October 07 Member No.: 4,011 |
I have several variables that I want to assign to various spans within a page (i.e. customer_name, customer_address, etc.). Now, I am going to have more than a 1 span that I dynamically need to assign the customer_name to. But I want it to be able to do so without me having to name them all "customer_name1, customer_name2, customer_name3" and then having to go through and manually change each one, one-by-one within the function.
What I'd like to do is ultimately have the function loop through every span with the name or id of "customer_name" and change the innerHTML within it to whatever the value of the costomer's name variable is ("John Doe" for example). I've tried a few ways, most of the time it only changes 1 instead of all of them. Can anyone help? _________________ bat control free windows registry cleaner |
pandy |
Oct 9 2007, 10:02 PM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,733 Joined: 9-August 06 Member No.: 6 |
What language do you have in mind?
|
Christian J |
Oct 10 2007, 07:18 AM
Post
#3
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
This sounds like javascript.
You can loop through the document.getElementsByTagName('span') array, and then check the className or ID of each SPAN item. Using CLASS names is probably easier, since you can only use an ID value for one element on a page. If you must use different IDs like "customer_name1", "customer_name2", "customer_name3" you might use some string comparison method to check if the "customer_name" part of the IDs match: http://www.quirksmode.org/js/strings.html |
Lo-Fi Version | Time is now: 28th April 2024 - 09:06 AM |