Solved

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

Posted on 2004-03-20
11
276 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now