Solved

populate values

Posted on 2012-03-23
7
208 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

831 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