?
Solved

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

Posted on 2004-03-20
11
Medium Priority
?
285 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introducing Priority Question, our latest feature.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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