Solved

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

Posted on 2004-03-20
11
279 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
object methods vs static methods 2 97
Spring MVC - sending raw charset to backend 3 199
spring example errors 33 317
servlet example 17 29
One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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