mardi 2 juin 2015

Selecting one checkbox each table row

  out.println("<html>");
    out.println("<head>\n"
            + "<script src=\"http://ift.tt/1xDNnh9\"></script>\n"
            + "<script>\n"
            + "$(function() {\n"
            + "  $('input[type=\"checkbox\"]')\n"
            + "    .on('change', function(){$('input[type=\"checkbox\"]').not(this).prop('checked', false);});\n"
            + "});\n"
            + "</script>\n"
            + "</head>");
    out.println("<body>");   

   while (itr.hasNext()) {
            Object o = itr.next();
            Element vraag = (Element) o;

            StringBuffer row = new StringBuffer("<tr>");

            row.append("<td>" + vraag.getChildText("VRAAG") + "</td>");
            String antwoord = vraag.getChildText("INVOERMOGELIJKHEID");

            if (antwoord.equals("tweecheckbox")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"tweecheckbox\" value=\"0\">" + "<input type=\"checkbox\" name=\"tweecheckbox\" value=\"1\">" + "</td>");
            } else if (antwoord.equals("driecheckbox")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"1\">" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"2\">");
            } else if (antwoord.equals("viercheckboxNT")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"viercheckboxNT\" value=\"0\">" + "<input type=\"checkbox\" name=\"viercheckboxNT\"value=\"1\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"2\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"3\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"\">" + "</td>");
            } else if (antwoord.equals("vijfcheckbox")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"vijfcheckbox\" value=\"0\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"1\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"2\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"3\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"4\">");
            } else if (antwoord.equals("tekstvak")) {
                row.append("<td>" + "<INPUT TYPE=\"text\" NAME=\"tekstvak\" SIZE=\"11\" MAXLENGTH=\"20\">");
            } else {
                row.append("<td>" + antwoord);
            }

            out.println(row.toString());

        }

In the code above i'm trying to make a form out of an xml-file in a java servlet.

The form is creating and working. However, i would like to check one checkbox every row. At the moment i can only select one checkbox in the whole form.

I think the creating of checkboxes in the while loop is the problem. However, i have to create 88 rows all with 5 checkboxes for this form. Is there a way to do this but will be able to select one checkbox every row?




Aucun commentaire:

Enregistrer un commentaire