0

I have an array list of two things on a form with a disabled button. I need to use jQuery to check which value is checked, and if a certain one is checked re-enable the submit button.

The model:

private List<String> billTypeOptions;

The controller:

List<String> billTypeList = new ArrayList<String>();
billTypeList.add("Direct Bill");
billTypeList.add("Agency Bill");
model.addAttribute("billTypeList", billTypeList);
ams360Policy.setBillTypeOptions(billTypeList);

The HTML:

<td id="billTypeCell">
  <div th:each="billType : ${billTypeList}">
      <input class="bto" type="checkbox" th:field="*{ams360Policies[__${stat.index}__].billTypeOptions}" th:value="${billType}" value="off"/>
      <label th:text="${billType}" id="billTypeLabel"></label>
  </div>
</td>

I've tried this:

if($('.bto').is(":checked"){
   $('#send').attr("disabled",false);
 }
But it seems to not work because the page needs to reload to register the checking. Any idea how to get this to work without reloading the page?

I've also tried

if ($('.bto').val() == 'Direct Bill")
if ($('.bto').value == 'Direct Bill")
Stacie
  • 306
  • 7
  • 26
  • 1
    You're repeating the bto id in the loop, and the billTypeLabel id – Taplar Nov 30 '18 at 21:15
  • ^ To fix the problem, change them to `class` attributes, and amend the selectors in your JS – Rory McCrossan Nov 30 '18 at 21:16
  • @Taplar, Oh sorry, yes I caught that and it still doesn't work. I will adjust the code. – Stacie Nov 30 '18 at 21:22
  • Also be aware that `.val()` isn't going to loop over the elements and find the one that matches, or return an array. It's only going to return the value for the first element in the result stack. – Taplar Nov 30 '18 at 21:23
  • So I've realized the issue I'm having with the above suggestions is that the page needs to be refreshed to be able to process the checking of the checkbox. Any idea how to fix this so the page doesn't need to be refreshed but can process the click function? Maybe instead of doing is("checked") I should do .click()? – Stacie Dec 17 '18 at 23:45

0 Answers0