Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Javascript to generate HTML that contains JSP
    primarykey
    data
    text
    <p>I am making a web view using jsp, javascript and html. I have a list of elements that when clicked on calls among other things the javascript function generatePictureSlider. The idea is that a set of pictures is associated with each element in the list and a slider is created when one of the elements is clicked on. </p> <p>This is the code that creates my list:</p> <pre><code>&lt;div class="valg"&gt; &lt;ol id="selectable"&gt; &lt;c:forEach items="${kandidatliste}" var="kjoretoy" varStatus="rowCounter"&gt; &lt;li id="${rowCounter.index}" class="ui-widget-content"&gt; &lt;c:choose&gt; /*Some code that displays content based on a variable in the kjoretoy var */ &lt;/c:choose&gt; &lt;c:out value="Reg nr: ${kjoretoy.kjennemerke} "/&gt; &lt;c:out value="Score: ${kjoretoy.score} "/&gt; &lt;c:out value="Passering: ${kjoretoy.passeringsString} "/&gt; &lt;input id="removeVehicle" type="submit" value="X" /&gt; &lt;input id="checkVehicle" type="submit" value="Sjekk"/&gt; &lt;/li&gt; &lt;/c:forEach&gt; &lt;/ol&gt; &lt;/div&gt; </code></pre> <p>The #selectable ol is bound to a click function in javascript. This click function is the one that calls on generatePictureSlider. So, when one of the elements in the list is clicked on, I want to display the pictures associated with the element in a slider. </p> <p>Thus, I have to generate the html that displays the slider dynamically. </p> <p>My problem is that I get this error: <code>java.lang.NumberFormatException: For input string: "+parseInt(index)+"</code></p> <p>Index here is naturally the index of the element that has been click, which corresponds to the place the element has in an arraylist which the view has received from the Java application. This arraylist is called "kandidatliste" as you will see in the function under. </p> <pre><code>function generatePictureSlider(index){ $('div#switcher-panel').html(''); var html = '&lt;div id="container"&gt;'+ '&lt;div id="banner"&gt;'+ '&lt;ul class="bjqs"&gt;'+ '&lt;li&gt;&lt;img src="/nonstop/bildekjennemerke=${kandidatliste['+parseInt(index)+'].kjennemerke}&amp;bildeNr=${0}" title="${kandidatliste[0].kjennemerke}_${0}" width="350" height="220"/&gt;&lt;/li&gt;'+ '&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;'; $('div#switcher-panel').append(html); } </code></pre> <p>How can I make the javascript variable index be an integer so that the JSP does not crash and shows the picture associated with the element in index index. </p> <p>I am of course open to other suggestions on how to solve it. The essence is that based on the element a user clicks on, I want to show images and other data associated with that element on the page. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload