Check form checkbox when the label is clicked


/ Published in: JavaScript
Save to your folder(s)

this is a way to deal with the fact that we can\'t reliably make checkboxes look larger on forms. So instead, we surround the form with a colored div, and set it up so that when the user clicks on the label next to the checkbox it checks the box.


Copy this code and paste it in your HTML
  1. <script>
  2. function radioME(){
  3. uncheckALL("j",3)
  4. arguments[0].checked=true
  5. return true
  6. }
  7.  
  8. function uncheckALL(){
  9. var currentId=0;
  10. for(currentId=0;currentId<arguments[1];currentId++){
  11. document.getElementById(arguments[0]+currentId).checked=false
  12. }
  13. }
  14. </script>
  15.  
  16. <div style="background-color: rgb(255, 255, 204); padding: 5px; font-size: 12px; border: thin solid rgb(102, 136, 0);">
  17. <label>
  18. <input type="checkbox" onclick="radioME(this)" id="j0" value="1" name="groups_KEY658_checkbox"/>
  19. <strong>Vote for Dan Seals</strong>
  20. </label>
  21. </div>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.