Link to home
Start Free TrialLog in
Avatar of dshrenik
dshrenikFlag for United States of America

asked on

Onclick with HTML

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!
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

You don't show the function!

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

More like function highlightSpot()
{
...
...
}
Avatar of dshrenik

ASKER

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".
I have an alert command as the first line of the function.

The alert works fine with numeric parameters but not otherwise.
ASKER CERTIFIED SOLUTION
Avatar of sammySeltzer
sammySeltzer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial