views:

100

answers:

2

Hi all,

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 to resolve it?

thanks in Advance

  • Gnaniyar Zubair
+2  A: 

I think you are missing quotes around your string:

<% String testing = "DSfsdsfd" ; %> <a
href="javascript:downloadPopup('<%=testing%>')"
> Click </a>
Pekka
THANKS Pekka. this is working fine.
Gnaniyar Zubair
A: 
downloadPopup('<%=testing%>')

dont forget to put string in ''

Aykut
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.
darkporter
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("'","\\\'") %>'
Aykut