0

Hi,

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

<html>
    <head>
        <title>Debugging</title>
        <script language="javascript">
            function changeOn(object, objectId) {
                alert('in function');
                if (object == 'bookingsButton') {
                    alert('first if');
                    document.getElementById(objectId).src = 'Images/BookingsOn.png';
                } else if (object == 'detailsButton') {
                    alert('2nd if');
                    document.getElementById(objectId).src = 'Images/DetailsOn.png';
                }
            }
            function changeOff(object, objectId) {
                if (object == 'bookingsButton') {
                    document.getElementById(objectId).src = 'Images/Bookings.png';
                } else if (object == 'detailsButton'){
                    document.getElementById(objectId).src = 'Images/Details.png';
                }
            }
        </script>
    </head>
    <body>
        <%
                    for (int i = 0; i < 2; i++) {
        %>
        <table>
            <tr>
                <td>
                    <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>
                </td>
                <td>
                    <a href="Details.jsp"><img src="Images/Details.png" id="details<%out.println("" + i);%>"/></a>
                </td>
            </tr>
        </table>
        <% }%>
    </body>
</html>

Thanks,
-Ashton

Edited by AshtonHogan: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by AshtonHogan
1

The use of out.println() adds a newline character causing erroneous syntax of the generated output.
The generated html is,

<img src="Images/Bookings.png" id="bookings0
" onmouseover="changeOn('bookingsButton','bookings0
')" onmouseout="changeOff('bookingsButton','bookings0
')"/>

There is a newline character after bookings0

Use out.print() instead. Which will generate html like,

<img src="Images/Bookings.png" id="bookings0" onmouseover="changeOn('bookingsButton','bookings0')" onmouseout="changeOff('bookingsButton','bookings0')"/>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.