Solved

populate values

Posted on 2012-03-23
7
205 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
Comment Utility
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
Comment Utility
Try this attached code
Friends.txt
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
@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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jcbmtt
Comment Utility
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
Comment Utility
Put the name in the title of the link
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
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
Comment Utility
exactly. thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now