Jump to content

Recommended Posts

Easy enough to do with jquery, something like....

 

$(document).ready(function() {
  $('#submittbn').submit(function() {
    $("input[type='checkbox']").not(':checked')).each(function() {
      $this.val(0).attr('checked', true);
    });
  });
});

jQuery is a library created by someone, you need to get the jQuery js file

 

but you can do it without jQuery, and probably with the same amount of code :)

 

 

Edit: Well, probably a couple lines more, but thats not the reason for my edit.. Thorpe's example (which is probably the only way to do it anyway.. minus the jquery) would set checked attribute to true, which will literally tick the checkbox you'd want to ALSO set the value of the checkbox to 0.. just a sidenote

you'd want to ALSO set the value of the checkbox to 0

 

Which is what this bit....

 

$this.val(0)

 

does.

 

wow jquery does it all huh.. so val() actually returns the updated element after the value change?

 

I personally never used jQuery :)

jQuery is a library created by someone, you need to get the jQuery js file

 

but you can do it without jQuery, and probably with the same amount of code :)

 

 

Edit: Well, probably a couple lines more, but thats not the reason for my edit.. Thorpe's example (which is probably the only way to do it anyway.. minus the jquery) would set checked attribute to true, which will literally tick the checkbox you'd want to ALSO set the value of the checkbox to 0.. just a sidenote

jQuery is a library created by someone, you need to get the jQuery js file

 

but you can do it without jQuery, and probably with the same amount of code :)

 

 

Edit: Well, probably a couple lines more, but thats not the reason for my edit.. Thorpe's example (which is probably the only way to do it anyway.. minus the jquery) would set checked attribute to true, which will literally tick the checkbox you'd want to ALSO set the value of the checkbox to 0.. just a sidenote

 

ily man

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.