Reputation: 15
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?
Upvotes: 1
Views: 141
Reputation: 195982
If SomeName
is not a variable defined previously, but it is the actual literal text you want to pass to the method, then you need to put it in quotes.
javascript:detailplace('SomeName');
Upvotes: 1
Reputation: 9763
SomeName
above is being used as a variable not as a string. You are missing quotes.
<a href="javascript:detailplace('SomeName');">Details</a>
Without quotes, it's looking for a variable called SomeName
that will hold the name of the place you want to fill. Know what I mean?
Upvotes: 1
Reputation: 16465
You have to wrap SomeName
with quotes
:
<a href="javascript:detailplace('SomeName');">Details</a>
When you pass it without quotes javascript
thinks that it is variable that is undefined
.
Upvotes: 2