call javascript function from jsp ?
843840Nov 23 2008 — edited Nov 23 2008Hi all, I am trying to call a javascript function from a jsp like this:
for (Object a:list)
{
ServerSide.courseBean temp=(ServerSide.courseBean)a ;
int id=temp.getId();
String name=temp.getName();
%>
<script type="text/javascript">
addElement(<%=id%>,<%=name%>);
</script>
<%
}
and the javascript function is this:
function addElement(id,name)
{
var ni = document.getElementById('parentDiv');
var newdiv = document.createElement('div');
var divIdName = id;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML ="<a href =\"javascript:;\" onClick=\"startRequest(\'"+id+"\')\">"+name+"</a>";
ni.appendChild(newdiv);
}
The problem is that when I pass a string parameter "name" (like this here) it doesn't work, although it works fine when passing only int "id". What's the problem here ?