Solved

populate values

Posted on 2012-03-23
7
211 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
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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