Solved

Onclick with HTML

Posted on 2012-03-22
4
231 Views
Last Modified: 2012-03-27
The following does not seem to work:
var rowHTML = '<td>' + '<a href="javascript:void(0)" onclick="highlightSpot(' + spot.name + ');">' + spot.name + '</a>' + '</td>' + '<td>'+distance+'</td>';

	var table = document.getElementById(tableID);
  	rowElement = document.createElement('tr');            
 	newRow = table.appendChild(rowElement);
	newRow.innerHTML = rowHTML;

Open in new window


The function highlightSpot() is not being called.
However, when I use onclick="highlightSpot()", the function is called.

Please let me know what the problem could be. Thanks!
0
Comment
Question by:dshrenik
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 37754285
You don't show the function!

Could it be that the function doesn't have a param?

More like function highlightSpot()
{
...
...
}
0
 

Author Comment

by:dshrenik
ID: 37754310
There's no problem wth the function. It works fine.

I narrowed down on the problem. When I pass a numeric parameter like "12" through onclick="highlightSpot(' + spot.name + ');", it works fine.

However, it does not work when I pass a text parameter like "ABC".
0
 

Author Comment

by:dshrenik
ID: 37754311
I have an alert command as the first line of the function.

The alert works fine with numeric parameters but not otherwise.
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 37754447
Well, you can try escapting the quotes like:

onclick='highlightSpot("""+ spot.name +""");'>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

759 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

23 Experts available now in Live!

Get 1:1 Help Now