Reputation: 457
I have the following span element defined in the view in the MVC app
<span id="openDocument"
class="fa fa-sign-in"
style="cursor:pointer;
color:#5d9cec"
data-toggle="tooltip"
onclick="openDocument(@item.formattedReference.ToString())")>
</span>
Javascript function:
function openDocument(documentId) {
debugger;
window.open("https://somelongURL/documentId=" + documentId);
};
The problem that I am having with this code is that this code works for document id that has numbers (eg. 12345) but it doesn't work for alphanumeric numbers (eg. R12345).
It gives me an error saying: Uncaught Reference Error: R12345 is not defined.
How do i solve this problem?
Thanks in advance.
Upvotes: 1
Views: 345
Reputation: 3457
Try to put your variable in quotes:
<span ... onclick="openDocument('@item.formattedReference.ToString()')"></span>
Unlike numbers, strings can only be passed in quotation marks.
Explanation:
Uncaught Reference Error: R12345 is not defined.
The error message contains all information about debugging, namely that the transmitted value is interpreted as a variable as soon as it contains letters. R12345
was interpreted as a variable.
Upvotes: 3