Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got expected expression, got end of script error when pass the data one function to another function.




cont += '<p><a href="javascript:onDisp('+filepath+ ')">' + DocHeader + '</a></p>';
Posted
Updated 23-Sep-15 18:42pm
v7
Comments
Mohibur Rashid 24-Sep-15 4:51am    
try this
cont += '<p>' + DocHeader + '</p>';
It would be better looking if,
var filepath_quoted = "'"+filepath+"'";
cont += '<p>' + DocHeader + '</p>';

1 solution

The issue is you are not passing the filepath variable properly. Currently when its passed to the function onDisp it would be considered as a variable and then it would through an expression error as the data passed is not in correct format.

So, lets say your file path is like:

JavaScript
var filepath = 'C://Test/image.jpj'


but it would be passed as

JavaScript
<p><a href="javascript:onDisp(C://Test/image.jpj)">asasa</a></p>


since the proper qoutes to the filepath variable is not provided.

So, you can resolve it like:-

JavaScript
cont += '<p><a href="javascript:onDisp(\''+filepath+ '\')">' + DocHeader + '</a></p>';


Then you can test it inside the onDisp like:

JavaScript
function onDisp(filepath){
    alert(filepath);

    // your code goes here
}


This will display correct output now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900