Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

call javascript function from jsp ?

843840Nov 23 2008 — edited Nov 23 2008
Hi 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 ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2008
Added on Nov 23 2008
3 comments
4,419 views