[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Onclick with HTML

Posted on 2012-03-22
4
Medium Priority
?
244 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 29

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 29

Accepted Solution

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

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

873 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