FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Change multiple span text to the same value

 


FUTURE
Here's what I need to do:

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?
_________________
Isuzu Pickup

Shared ownership spain


Last edited by FUTURE on Wed Aug 29, 2007 10:08 am; edited 2 times in total
blueray
Code:
<html>
<head>
</head>
<body>
<div id="userinfo">
   <span>Item 1</span><br />
   <span>Item 2</span><br />
   <span>Item 3</span><br />
</div>
<script type="text/javascript">
<!--
data = new Array(3);

data['Customer_name'] = 'Peter Chan';
data['Customer_address'] = 'USA 1A';
data['Customer_phone'] = '999999999';


//info = document.getElementById("userinfo");
spanelem = document.getElementById("userinfo").getElementsByTagName('SPAN');

i = 0;
for (p in data)
{
   spanelem[i].innerHTML = data[p];
   ++i;
}

//-->
</script>
</body>
</html>


This may be help.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.