0

I've got a checkbox, which is default "checked" - Its "POST" enable=true Second, I've got a checkbox, which is hidden. - This must "POST" enable=false

<td>
    <input style="margin-left: -100px" id='checked' type='checkbox' value='true' name='enable'>
    <input id='not_checked'  type='hidden' value='false' name='enable'>
</td>

So, if the checkbox have an attribute "checked" - my script is working and send enable=true. But if, I doesn't check the box, my script stop working and doesn't send everything.

JS:

if(document.getElementById("checked").checked) {
    document.getElementById('not_checked').disabled = true;
}

I have taken the example from here:

Post the checkboxes that are unchecked

Community
  • 1
  • 1
pastuh
  • 41
  • 1
  • 1
  • 6
  • you have `name='enable'` for both this is invalid. when checked it is working because you are disabling the second input and thus effectively having only one item with `name='enable'` to post. – bansi Sep 15 '14 at 12:44
  • Can I use and if $("#checked").attr("checked") == "checked" + "&" + "enable=true"; else $("#checked").attr("checked") == "undefined" + "&" + "enable=false"; – pastuh Sep 15 '14 at 13:20

1 Answers1

0

try this code .. i think this will do the job

<td>
<input id='checked' type='checkbox' value='true' name='checked' style="margin-left: -100px">
<input id='not_checked'  type='hidden' value='false' name='checked'>
</td>
AlhasanIQ
  • 183
  • 2
  • 9
  • yes, this works. But, when I edit the "name" of it, its doesn' work anymore. Its not good, because I need - name="enable" – pastuh Sep 15 '14 at 12:46
  • if you want to change the name you got to change the id i think you want this ' > – AlhasanIQ Sep 15 '14 at 12:56
  • Can I use and if $("#checked").attr("checked") == "checked" + "&" + "enable=true"; else $("#checked").attr("checked") == "undefined" + "&" + "enable=false"; – pastuh Sep 15 '14 at 13:20