Note that there are some explanatory texts on larger screens.

plurals
  1. POaccess javascript variable value in jsp
    primarykey
    data
    text
    <p>I want to pass a javascript variable to my servlet, where I need to use it. </p> <p>In javascript, the variable <em>count</em> returns the rows of my table and I can show <em>count</em> in the jsp, using <code>$('#counter').html(count);</code> , but I cannot pass <em>count</em>'s value to my servlet. I tried <code>document.getElementById("hiddenField").value=count;</code> but it doesn't work.</p> <p><strong>Javascript</strong></p> <pre><code>&lt;script&gt; var count = 3; $(function() { $('#counter').html(count); $('#addButton').bind('click', function() { count = document.getElementById("dataTable").getElementsByTagName("tr").length; $('#counter').html(count); }); $('#deleteButton').bind('click', function() { count = document.getElementById("dataTable").getElementsByTagName("tr").length; $('#counter').html(count); }); }); document.getElementById("hiddenField").value=count; // ??? &lt;/script&gt; </code></pre> <p><strong>JSP</strong></p> <pre><code>Count: &lt;span id="counter"&gt;&lt;/span&gt; &lt;%-- it works --%&gt; &lt;form method="post" action="newteamsubmit"&gt; ... &lt;input type="hidden" id="hiddenField" name ="countRows" /&gt; &lt;input type="submit" name ="button1" value=" Submit " /&gt; &lt;input type="submit" name = "button1" value=" Cancel " /&gt; &lt;/form&gt; </code></pre> <p><strong>Servlet</strong></p> <pre><code>String cr = request.getParameter("countRows"); //I' ve tried also to convert it // to int, but that's not my problem, since I cannot pass the value as a start </code></pre> <p>I've spent many hours, trying to figure out how I can access a javascript variable in jsp, but I haven't found any solution. Thanks in advance.</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.
 

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