Link to home
Start Free TrialLog in
Avatar of jcbmtt
jcbmtt

asked on

populate values

i am trying to populate list of friends numbers (1,2,3,4,6) as links and show their names (friend name 1, friend name 2 etc ) in a tooltip on mouseover. pl advice.

<html>
<head>
<script>
for (var i=0; i < 6; i++)	
					{
friends.innerHTML += "<a href='javascript:void();'>" + friends[i].name + "</a>";
					}
</script>
</head>
<body>
<div id="friends></div>
</body>
</html>

Open in new window

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

1) document.getElementById("friends").innerHTML
2) you need to do this onload
3) you need an object array

DEMO

<html>
<head>
<script>
var friends = [
{name:"Tom"},
{name:"Dick"},
{name:"Harry"}
];
window.onload=function() {
  var div = document.getElementById("friends");
  for (var i=0, n=friends.length; i < n; i++)	{
    div.innerHTML += '<a href="#" onclick="return false">' + friends[i].name + '</a>';
  }
}
</script>
</head>
<body>
<div id="friends"></div>
</body>
</html>

Open in new window

Avatar of sankhe_dipti
sankhe_dipti

Try this attached code
Friends.txt
@sankhe_dipti
1) Why attach a file when you can post the code
2) you are not adding anything to the discussion:
You do not access the div correctly
You use javascript: prefix which is not necessary
You add complexity with visibility and show/hide
Avatar of jcbmtt

ASKER

mp,

i am looking for tooltip to show corresponding names to the links. i am not able to see that in the code.

my question again :

i am trying to populate list of friends numbers (1,2,3,4,6) as links and show their names (friend name 1, friend name 2 etc ) in a tooltip on mouseover. pl advice.
Put the name in the title of the link
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jcbmtt

ASKER

exactly. thanks.