Solved

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

Posted on 2004-03-20
11
277 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

911 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

22 Experts available now in Live!

Get 1:1 Help Now