dshrenik
asked on
Onclick with HTML
The following does not seem to work:
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!
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;
The function highlightSpot() is not being called.
However, when I use onclick="highlightSpot()",
Please let me know what the problem could be. Thanks!
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 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".
ASKER
I have an alert command as the first line of the function.
The alert works fine with numeric parameters but not otherwise.
The alert works fine with numeric parameters but not otherwise.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Could it be that the function doesn't have a param?
More like function highlightSpot()
{
...
...
}