0

I've list from db and put in json list with checkbox and the value. I need the value for insert to table db. So, how to get value from the selected checkbox in java? Thanks a lot.

In JSP File

function refreshList() {
  var collection = "";
  collection = collection
  + " <table><thead><th class='LIST'><span><label>Selection</span></label></th><th class='LIST'><span><label>List</span></label></th></thead><tbody>";

  var isnew = $("input:radio[name=isnew ]:checked").val();
  var string = "";
  $.getJSON('${pageContext.request.contextPath}/master.do?reqcode=refreshList', {
    'isnew ' : isnew
  }, function(result) {
    $.each(result,function(key,value) {
      string = string + "<tr><td> "
      + "<input id='id' type='checkbox' value=" + key + "/></td>" + "<td> " + value
      + "</td></tr>";
    });

    collection = collection + string + " </tbody></table> ";
    $('#collectionid').html(collection);
  });
}
<div id="collectionid"></div>

1
  • Are you using some server side framework on java? Commented Jan 12, 2017 at 11:45

1 Answer 1

1

You need to have a name attribute on the checkbox.

<input name="chkBox" type="checkbox" value="xxx" />

You can get the checkbox value from servlet request object as shown below:

String[] values = request.getParameterValues("chkBox");
Sign up to request clarification or add additional context in comments.

1 Comment

This really helpful. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.