Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Select/Unselect ALL Checkboxes

I have tried probably over around 10 different Javascript and JQuery scripts for this and haven't been able to get one to work. This is my current script:

Here's the JQuery import...
Code
<html>
<head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script></head></html>

Here's the function...
Code
<script>
function toggleChecked(status) {
$("#checkboxes input").each( function() {
$(this).attr("checked",status);
})</script>

And here's the HTML...
Code
<input type="checkbox" onclick="toggleChecked(this.checked)"> Select / Deselect All
<div id="checkboxes">
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox" />
<input type="checkbox" class="checkbox" />
</div>

It makes all of the check boxes but when you click the select all, it doesn't do a thing to the other boxes.
You forgot to close your function's brace.
Why not just using something simple like this http://jsfiddle.net/xHCwJ/
(Aug 20, 2013 09:32 PM)Dave85 Wrote:  You forgot to close your function's brace.
Why not just using something simple like this http://jsfiddle.net/xHCwJ/
The fiddle you posted didn't work either. :/

The code I added:
Code
<script language="javascript">
$('#checkall:checkbox').change(function () {
    if($(this).attr("checked")) $('input:checkbox').attr('checked','checked');
    else $('input:checkbox').removeAttr('checked');
});</script>

<input type="checkbox" name="all" id="checkall" />Check All</br>

<input type="checkbox" class="cb-element" /> Checkbox  1</br>
<input type="checkbox" class="cb-element" /> Checkbox  2</br>
<input type="checkbox" class="cb-element" /> Checkbox  3
I updated with a new fiddle:http://jsfiddle.net/xHCwJ/388/
Also use <script type="text/javascript"> not <script language="javascript">
And you call the script after page loaded.
(Aug 20, 2013 11:12 PM)Dave85 Wrote:  I updated with a new fiddle:http://jsfiddle.net/xHCwJ/388/
Also use <script type="text/javascript"> not <script language="javascript">
And you call the script after page loaded.
It's still not working. :(

Like I said, I've tried sooo many different scripts. I have no idea what's wrong.
I guess you wait me to post code ?

Code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#checkall').on('click', function () {
  $("#yourform").find(':checkbox').prop('checked', this.checked);
        });
})
</script>
</head>
<body>
<form id="yourform">
<input type="checkbox" name="all" id="checkall" />Check All</br>
<input type="checkbox" class="cb-element" /> Checkbox  1</br>
<input type="checkbox" class="cb-element" /> Checkbox  2</br>
<input type="checkbox" class="cb-element" /> Checkbox  3
</form>
</body>
</html>
(Aug 20, 2013 11:28 PM)Dave85 Wrote:  I guess you wait me to post code ?

Code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#checkall').on('click', function () {
  $("#yourform").find(':checkbox').prop('checked', this.checked);
        });
})
</script>
</head>
<body>
<form id="yourform">
<input type="checkbox" name="all" id="checkall" />Check All</br>
<input type="checkbox" class="cb-element" /> Checkbox  1</br>
<input type="checkbox" class="cb-element" /> Checkbox  2</br>
<input type="checkbox" class="cb-element" /> Checkbox  3
</form>
</body>
</html>
I put exactly every thing you have there into file and it still isn't working. Do you think it's because it's a .php file?
just save it as file.html and then open.
(Aug 20, 2013 11:38 PM)Dave85 Wrote:  just save it as file.html and then open.
That's what I did. And I just said it fucks up all of my other stuff. In uBot, it does what I'm wanting it to do. Select users from a table based on attributes. And it was working in .php file type. So there should be a way to get it to work without renaming it to .html right?

This is what it does when I rename it to .html.

[Image: c902ab5bbd4050bfaa6fc631cdac0822.png]
Fit the previous script with yours, dont change anything.
(Aug 21, 2013 12:29 AM)Dave85 Wrote:  Fit the previous script with yours, dont change anything.
I did! And I know I didn't mess it up cause when I changed the extension to .html the checkboxes worked fine! It just screwed up everything else.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by HotTunaCanSandiwchJan 19, 2020 09:00 PM 2 92 Jan 19, 2020 09:00 PM
Last Post: al5ina5
[MyBB] by S Malkiq SamMar 8, 2016 06:31 PM 3 91 Mar 8, 2016 06:31 PM
Last Post: Wires
by Crypto™Jan 25, 2015 11:10 PM 15 454 Jan 25, 2015 11:10 PM
Last Post: Crypto™