I’m extremely frustrated by a couple of functions in my code. I have a couple of functions that fire when a user clicks on a link.
The parameter is correctly sent to both function but when the user clicks the link for detailplace I get a reference error, that SomeName is undefined. The function detail seems to work without a problem. Why does detail work but detailplace does not?
HTML
<a href="javascript:detail(123456);">Details</a>
<a href="javascript:detailplace(SomeName);">Details</a>
Javascript
function detail(property) {
var summaryhtml = '<iframe src="' + URL + property + '" width="340px" height="400px" frameborder="0" class="sum_frame"></iframe>';
document.getElementById('itab1').innerHTML = summaryhtml;
}
function detailplace(place) {
var summaryhtml = '<iframe src="' + URL + place + '" width="340px" height="400px" frameborder="0" class="sum_frame"></iframe>';
document.getElementById('itab1').innerHTML = summaryhtml;
}
I took your advice and edited the code to include quotes. The problem is that I’m construting the links in javascript. SomeName is defined elsewhere as a string.
link = '<a href="javascript:detailplace("';
link += SomeName;
link += '")";>Site Details</a>';
What is the right way to escape the quotes within quotes within quotes so I can send the string as a parameter?
You have to wrap
SomeNamewithquotes:When you pass it without quotes
javascriptthinks that it is variable that isundefined.