Note that there are some explanatory texts on larger screens.

plurals
  1. POAssign different id to forms using jsp
    text
    copied!<p>In each iteration I need to assign a new id to each form. Can you help me? Thanks.</p> <pre><code>&lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;JSP Page&lt;/title&gt; &lt;script language="JavaScript"&gt; function fnSubmit(){ var form1Content = document.getElementById("form1").innerHTML; var form2Content = document.getElementById("form2").innerHTML; document.getElementById("toSubmit").innerHTML=form1Content+form2Content; document.forms.toSubmit.submit(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table border="2"&gt; &lt;% int n = (Integer)session.getAttribute("num_apostes"); for (int i=0; i&lt;n; i++) { %&gt; &lt;tr&gt; &lt;td&gt; &lt;form name="form" id="&lt;%= "form"+ String.valueOf(i+1) %&gt;" method="POST" action="/Apostes/protegit/apostar"&gt; &lt;p&gt; &lt;input type="radio" name="&lt;%="r1_ap"+String.valueOf(i+1)%&gt;" value="1"&gt;1 &lt;input type="radio" name="&lt;%="rX_ap"+String.valueOf(i+1)%&gt;" value="X"&gt;X &lt;input type="radio" name="&lt;%="r2_ap"+String.valueOf(i+1)%&gt;" value="2"&gt;2 &lt;/p&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% } %&gt; &lt;/table&gt; &lt;input type="submit" value="submit" onclick="javascript:fnSubmit();"/&gt; &lt;form id="toSubmit" method="POST" action="/Apostes/protegit/apostar" style="display:none"&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>The problem is that I need to do a submit of all forms at the same time, but the function 'fnSubmit' does not recognize the IDs of forms. In this example I suppose that n is 2 so the function does not have an iterator.</p>
 

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