Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

populate values

Posted on 2012-03-23
7
Medium Priority
?
213 Views
Last Modified: 2012-03-24
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

0
Comment
Question by:jcbmtt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37756187
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

0
 

Expert Comment

by:sankhe_dipti
ID: 37756467
Try this attached code
Friends.txt
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37756485
@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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jcbmtt
ID: 37761202
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37761381
Put the name in the title of the link
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 37761459
Like this

<html>
<head>
<script>
var friends = [
{name:"Tom",number:123131},
{name:"Dick",number:5564564356},
{name:"Harry",number:45356345}
];
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" title="'+friends[i].name+'">' + friends[i].number + '</a>';
  }
}
</script>
</head>
<body>
<div id="friends"></div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:jcbmtt
ID: 37761491
exactly. thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question