Solved

why the codes inside of the javascrip does not work sometimes?

Posted on 2004-03-20
11
284 Views
Last Modified: 2010-04-01
Hi experts,

I have some JSP codes embedded insdie javascrip, which populate the select field when user click on a button.

Very strangely, the same codes work on one machine, but failed on other machine. Is there any suggestion about this? thanks.
0
Comment
Question by:panpanW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10641885
are they both running the same browser?

whats the error?
0
 

Author Comment

by:panpanW
ID: 10641947
yes,

the javascript just does not work, with an error "error on the page".
If I try to print something by System.out.println() within the JSP, which is inside of the javascript, then it will not print. the javascript will work if they are OUTSIDE of the <%%>, but the codes inside the <%%> just does not get executed.
0
 
LVL 92

Expert Comment

by:objects
ID: 10641960
can u post your code.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:panpanW
ID: 10641993

I have tracked down the problem to this line:
 
 str = str+"<option><%=e%></option>";

the complete javascript codes are like this:

function fnAddEquip()
 {
 var str;
 var cnt = document.getElementById("tabEquip").rows.length+1;
   str = "<TABLE width=550 cellpadding=0 cellspacing=0 border=0>";
   str = str + "<span id='erow'+cnt>";
   str = str + "<tr><td><input name='cbEquip' type='checkbox' value=cnt></td><td><select name='equipment' STYLE='width: 160px'>";
   <%
   ArrayList b = equipBean.findAllEquip();
   Iterator ltr = b.iterator();
   while(ltr.hasNext())
   {
    String e = (String)ltr.next();
       %>
   str = str+"<option><%=e%></option>";
   <%} %>
   str = str + "</select></td><td><input type='text' size=24 name='protocol'></td><td><input type='text' size=50 name='description'></td></tr></span></table>";
   tabEquip.insertAdjacentHTML("AfterEnd",str);
 }
0
 
LVL 92

Expert Comment

by:objects
ID: 10642005
> <%=e%>

You can't use that there.
jsp is executed on the server. Whereas javascript is executed on the client.
0
 

Author Comment

by:panpanW
ID: 10642014
so, why it works on the other machine?

How to work around this?
0
 
LVL 92

Expert Comment

by:objects
ID: 10642028
i may have misunderstood you, can you post the javascript code from the generated html file.
0
 

Author Comment

by:panpanW
ID: 10642068

thanks. actually, the values got retrieved correctly, but just the line gets split into two lines, is this the problem? PLease check the lines marked with ******
how to fix it?




function fnAddEquip(){
 var str;
 var cnt = document.getElementById("tabEquip").rows.length+1;
   str = "<TABLE width=550 cellpadding=0 cellspacing=0 border=0>";
   str = str + "<span id='erow'+cnt>";
   str = str + "<tr><td><input name='cbEquip' type='checkbox' value=cnt></td><td><select name='equipment' STYLE='width: 160px'>";
    alert("hi   1");
   
***   str = str+"<option>SEIKO Robot </option>";
   
***   str = str+"<option>Assay TekBench </option>";
   
*** str = str+"<option>CyBi-Well 96</option>";
   
*** str = str+"<option>EPSON Robot
</option>";
   
*** str = str+"<option>CyBi-Well vario
</option>";
   
   str = str + "</select></td><td><input type='text' size=24 name='protocol'></td><td><input type='text' size=50 name='description'></td></tr></span></table>";
   tabEquip.insertAdjacentHTML("AfterEnd",str);
 }
 
0
 
LVL 92

Accepted Solution

by:
objects earned 75 total points
ID: 10642083
try:

str = str+"<option><%= e.trim() %></option>";
0
 

Author Comment

by:panpanW
ID: 10642104
thanks,
but, I still don'w know why this happen? why one sting has extra space at the end?
0
 
LVL 92

Expert Comment

by:objects
ID: 10642115
No idea, check when the ArrayList is populated.
Good to hear it resolved your problem though :)

http://www.objects.com.au/staff/mick
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question