2

I am passing String parameter into javascript . But it is not being called. this is my script:

function downloadPopup(testing){      
alert(testing); }

I am calling the javascript like this from my jsp page:

<% String testing = "DSfsdsfd" ; %> <a
href="javascript:downloadPopup(<%=testing%>)"
> Click </a>

How can I resolve it?

2 Answers 2

3

I think you are missing quotes around your string:

<% String testing = "DSfsdsfd" ; %> <a
href="javascript:downloadPopup('<%=testing%>')"
> Click </a>
Sign up to request clarification or add additional context in comments.

Comments

0
downloadPopup('<%=testing%>')

dont forget to put string in ''

2 Comments

This works unless the string itself has quotes in it. Whatever language or web framework you're in probably has a "to_json" method. Call that on the string and it quotes it and escapes the quotes for you.
You're right darkporter. If the string has quotes in it you'll get a js error. If C# you can escape quotes as follows. '<%=testing.Replace("'","\\\'") %>'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.