943,097 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 2683
  • JSP RSS
Jan 28th, 2010
0

Javascript/JSP Error

Expand Post »
Hi,

I have pasted my code below, please paste it into a JSP and tell me why it gives the error "Unterminated String Constant"

JSP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Debugging</title>
  4. <script language="javascript">
  5. function changeOn(object, objectId) {
  6. alert('in function');
  7. if (object == 'bookingsButton') {
  8. alert('first if');
  9. document.getElementById(objectId).src = 'Images/BookingsOn.png';
  10. } else if (object == 'detailsButton') {
  11. alert('2nd if');
  12. document.getElementById(objectId).src = 'Images/DetailsOn.png';
  13. }
  14. }
  15. function changeOff(object, objectId) {
  16. if (object == 'bookingsButton') {
  17. document.getElementById(objectId).src = 'Images/Bookings.png';
  18. } else if (object == 'detailsButton'){
  19. document.getElementById(objectId).src = 'Images/Details.png';
  20. }
  21. }
  22. </script>
  23. </head>
  24. <body>
  25. <%
  26. for (int i = 0; i < 2; i++) {
  27. %>
  28. <table>
  29. <tr>
  30. <td>
  31. <a href="Bookings.jsp"><img src="Images/Bookings.png" id="bookings<%out.println("" + i);%>" onmouseover="changeOn('bookingsButton','bookings<%out.println("" + i);%>')" onmouseout="changeOff('bookingsButton','bookings<%out.println("" + i);%>')"/></a>
  32. </td>
  33. <td>
  34. <a href="Details.jsp"><img src="Images/Details.png" id="details<%out.println("" + i);%>"/></a>
  35. </td>
  36. </tr>
  37. </table>
  38. <% }%>
  39. </body>
  40. </html>

Thanks,
-Ashton
Last edited by AshtonHogan; Jan 28th, 2010 at 7:01 am.
Similar Threads
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
AshtonHogan is offline Offline
209 posts
since Jul 2009
Jan 28th, 2010
1
Re: Javascript/JSP Error
The use of out.println() adds a newline character causing erroneous syntax of the generated output.
The generated html is,
JSP Syntax (Toggle Plain Text)
  1. <img src="Images/Bookings.png" id="bookings0
  2. " onmouseover="changeOn('bookingsButton','bookings0
  3. ')" onmouseout="changeOff('bookingsButton','bookings0
  4. ')"/>
There is a newline character after bookings0

Use out.print() instead. Which will generate html like,
JSP Syntax (Toggle Plain Text)
  1. <img src="Images/Bookings.png" id="bookings0" onmouseover="changeOn('bookingsButton','bookings0')" onmouseout="changeOff('bookingsButton','bookings0')"/>
Sponsor
Reputation Points: 26
Solved Threads: 41
Junior Poster
parry_kulk is offline Offline
166 posts
since Jan 2007
Jan 28th, 2010
0
Re: Javascript/JSP Error
You're a genius. Thanks a lot man.
Reputation Points: 7
Solved Threads: 1
Posting Whiz in Training
AshtonHogan is offline Offline
209 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: calling a class from a JSP page
Next Thread in JSP Forum Timeline: Improving Security





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC