Solved

Onclick with HTML

Posted on 2012-03-22
4
232 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now