javascript uncheck ckeck boxes

I need a javascript function that will uncheck all checkboxes in a form... the the form name is form has other text and radio button inputs

Any ideas?
robrodpProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
I had to modify @leakim971's code to get it to work:  http://jsbin.com/aMuboPE/1/edit

function setAllCheckboxes(state) {
  var myform = document.getElementsByTagName('form')[0];
  var inputs = myform.getElementsByTagName("input");
  for(var i=0;i<inputs.length;i++) {
    console.log(inputs[i].type);
    if(inputs[i].type === "checkbox") {
      inputs[i].checked = state;
    }
  }
}

Open in new window


  <input type="button" value="check all" onclick='setAllCheckboxes("checked")' />
  <input type="button" value="uncheck all" onclick='setAllCheckboxes("")' />
  <form action="" name="form">
    <input type="checkbox">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox" checked="checked">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    <input type="checkbox">checkbox<br/>
    
  </form>

Open in new window

0
Julian HansenCommented:
With JQuery you could do it like this
<!doctype html>
<html>
<head>
<title>EE Q28226389</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
    $('button').click(function() {
        $(':checkbox').attr('checked', false);
    });
});
</script>
</head>
<body>
    <button>Clear them</button><br/>
    <input type="checkbox" id="cb1" > Checkbox 11</br>
    <input type="checkbox" id="cb2" > Checkbox 12</br>
    <input type="checkbox" id="cb3" > Checkbox 13</br>
    <input type="checkbox" id="cb4" > Checkbox 14</br>
    <input type="checkbox" id="cb5" > Checkbox 15</br>
    <input type="checkbox" id="cb6" > Checkbox 16</br>
</body>
</html>

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Julian HansenCommented:
@robrodp when you open duplicate questions you waste our time and cause confusion.

When you give B grades without a reason you insult us.
0
RobOwner (Aidellio)Commented:
And accept a solution that clearly is not a solution. +1 Julian.
0
leakim971PluritechnicianCommented:
+2
0
robrodpProgrammerAuthor Commented:
The solution in this post looks very much as the sulution that works off the bat. I feel that it is my lack ok javascript knowledge to implement it.

So I thought that I would accept it as a solution that I couldn´t implement (it looks like the other solution that worked off the bat). So in my eyes:

It was a solution (though ot sure)
Not simple enough for me to implement

So I accepted it and graded it B

The confusion arising from the duplicate is my fault, I wanted to word it in simpler terms to get a simpler solution, which happened.

Sorry about that.
0
robrodpProgrammerAuthor Commented:
What do the +1 or +2 mean?
0
Julian HansenCommented:
+1 is the EE equivalent of like or thumbs up. +2 same.

The solution in this post looks very much as the sulution that works off the bat. I feel that it is my lack ok javascript knowledge to implement it.
Then post back and ask

You were given three solutions here that all work. Tagit and Leakim971 are both highly qualified and respected experts - 99.99% of the time their solutions will work out of the box.

Not simple enough for me to implement
Not sure how to make it more simple - if that was too complex chances are you are swimming in the wrong pool.
The confusion arising from the duplicate is my fault, I wanted to word it in simpler terms to get a simpler solution, which happened.
For future reference - make sure you close a question before opening one that deals with the same topic. The usual practice is to wrap up with experts in the one thread and inform them you are opening another and optionally post a link to that the new thread so you can get some continuity from one to the other.

Here is more information on grading http://support.experts-exchange.com/customer/portal/articles/481419

If you find you are having difficulty integrating a solution then post back with the code you have attempted and ask us to help you - the best way to learn is to do and even if you don't get it right first time it will

a) Be easier for us to help you from where you have got to
b) Ultimately you will benefit from the exercise.
0
robrodpProgrammerAuthor Commented:
You are right...

My mistake. I got confused.

Will try better

Thx
0
robrodpProgrammerAuthor Commented:
Ok I understand

Wll delete

Yhx
0
robrodpProgrammerAuthor Commented:
I've requested that this question be deleted for the following reason:

Moderator suggested this question be deleted.
0
Julian HansenCommented:
Say what now -  why are we deleting this ?

This was the first thread - you open a new thread - give points there - receive a bunch of answers here and then this must be deleted - I think not.

I recommend you split points between Leakim, Tagit and Julianh.

Will wait for responses from other experts but not sure why we must take the hit because you opened a duplicate question?

If any question should be deleted it is the second one.
0
robrodpProgrammerAuthor Commented:
I deleted this question as I understood as suggested by a moderator. If I delete the second question I might get a similar objection.

I can delete both delete none delete the forst or delete the second one. All will be received with objections by by moderators or or other exprets that participated in the question.

I mean I understand all this issue but cant find a way out.

I apologized, committed to be more careful.
0
robrodpProgrammerAuthor Commented:
Ok... I will split points... not sure how to do it...
0
Julian HansenCommented:
Select Accept Multiple Solutions

Select the the one you want as the accepted - put points split in the boxes provided.
0
robrodpProgrammerAuthor Commented:
Done...
0
robrodpProgrammerAuthor Commented:
Hi

I cannot find #a39458830 in the comments to my question. I accepted 3 multiple solutions all of which are valid technical comments. Am I wrong?
0
robrodpProgrammerAuthor Commented:
Thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.