Farid Valiyev
Farid Valiyev

Reputation: 203

How can I submit multiple forms that come from a for loop in a click of one button in JSP

HTMLs that come from Database are being written to the screen by a for loop. Some of these HTMLs need to be submitted. What is wrong with the code?

<body>
    <%  int i;
        if (books != null) {
            for (i = 0; i < books.size(); i++) {
    %> 
    <hr>  

    <form class ="container" action="jspCheckBox.jsp" method="get" id="<%=i%>">

        <%
            if (books.get(i).getId() == null) {
                out.print("Axtardiginiz melumat tapilmadi");

            } else {
                out.print(books.get(i).getId());
            }
        %>

        <input type="checkbox" name ="id" value="<%=i%>"> Seç<br>
        <input  type="submit" style="display:none">

    </form> 
        <input  type="submit" form="<%=i%>" value = "Submit">

    <%
         }

      }

    %>

    <hr>

Upvotes: 0

Views: 563

Answers (1)

Farid Valiyev
Farid Valiyev

Reputation: 203

I'm fix it.

 <form class ="container" id ="form" action="jspCheckBox.jsp" method="get">
        <%
            for (i = 0; i < books.size(); i++) {

                if (books.get(i).getId() == null) {
                    out.print("Axtardiginiz melumat tapilmadi");
                } else {
                    out.print(books.get(i).getId());
                }
        %>
        <input type="checkbox" value="<%=i%>" name ="id" > Seç   

        <%
            }
        %>
        <input  type="submit" value = "Selected " >
    </form> 

Upvotes: 1

Related Questions