Solved

Javascript Select/Deselect checkbox

Posted on 2009-05-13
9
659 Views
Last Modified: 2012-05-06
I have a list of checkboxes.  I already have a code that does Select/Deselect all.  Pretty much all that code does is toggle the status.  

What I need is a true Select/Deselect all code.

So when you check the box to Select All, if any boxes are currently checked, it would leave them alone.  Any boxes that aren't checked, it would check them.  

Same for Deselect.  If you uncheck the box, then any boxes that are currently checked would uncheck.  Any boxes that are currently unchecked would remain unchecked.
0
Comment
Question by:nikinik
  • 5
  • 4
9 Comments
 
LVL 7

Expert Comment

by:Jonah11
ID: 24377281
0
 

Author Comment

by:nikinik
ID: 24378801
That code doesn't seem complete or well laid out.  I cannot get it to work.
0
 
LVL 7

Expert Comment

by:Jonah11
ID: 24378872
paste in everything you have so far.  ill fix it.
0
 

Author Comment

by:nikinik
ID: 24379051
I have this and it works....but it's individual buttons to select all and deselect all.  I really would rather it just be one checkbox to select all or deselect all.  


<SCRIPT LANGUAGE="JavaScript">

function checkAll(field)

{

for (i = 0; i < field.length; i++)

	field[i].checked = true ;

}
 

function uncheckAll(field)

{

for (i = 0; i < field.length; i++)

	field[i].checked = false ;

}
 

</script>
 

<input type="button" name="CheckAll" value="Select All" onClick="checkAll(document.tstest.bApproved)">&nbsp;

<input type="button" name="UnCheckAll" value="Deselect All" onClick="uncheckAll(document.tstest.bApproved)">

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Accepted Solution

by:
Jonah11 earned 500 total points
ID: 24379320
click on bottom checkbox
<form name="myform" action="checkboxes.asp" method="post">

<b>Your Favorite Scripts & Languages</b><br>

<input type="checkbox" name="list" value="1">Java<br>

<input type="checkbox" name="list" value="2">Javascript<br>

<input type="checkbox" name="list" value="3">Active Server Pages<br>

<input type="checkbox" name="list" value="4">HTML<br>

<input type="checkbox" name="list" value="5">SQL<br>
 

<input type="checkbox" name="checkUncheck" onChange="updateChecks(document.myform.list, this)">

</form>
 

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function updateChecks(field, controllerCheckbox) {

	var checkValue = controllerCheckbox.checked;

	for (i = 0; i < field.length; i++) {

		field[i].checked = checkValue ;

	}

}

//  End -->

</script>

Open in new window

0
 

Author Comment

by:nikinik
ID: 24379461
I copied and pasted your code directly and it doesn't work...

http://dev.c2trak.clickclaims.com/test.asp
0
 
LVL 7

Expert Comment

by:Jonah11
ID: 24379538
that is not my code.  go to view source and compare it with whats above.
0
 

Author Comment

by:nikinik
ID: 24379633
I was able to modifiy the code and get it working.
0
 
LVL 7

Expert Comment

by:Jonah11
ID: 24379663
ok glad i could help.  but if you select all on that code, paste it into a blank notepad, and save it as test.html, it will work.  something must have happened when you put the code on your asp page.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get values from jscript datepicker in form 3 290
HTML coding help 6 65
js file for one script block only 4 141
jquery toggle display styling 5 83
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now