dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersnaveensanagasetti
Toynbeelee
Sidharthan
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » TypeScript » Scripting Languages » Javascript

How to select and unselect checkbox using Java script


Posted Date:     Category: Javascript    
Author: Member Level: Gold    Points: 8


In this article I have explained about how to select and unselect checkbox values using Java script



 



In this article I have explained about how to select and unselect checkbox values
using Java script. Just drag and drop two button control and checkbox control.
In button click event just call ChangecheckboxStateToTrue() to make all checkbox to true.
In another button click event just call ChangecheckboxStateToFalse() to make all checkbox to false.




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>

<script type="text/javascript">
function ChangecheckboxStateToTrue(frmname)
{

var totalcheckvalus= document.getElementById(frmname);
for (var i =0; i < totalcheckvalus.elements.length; i++)
{
totalcheckvalus.elements[i].checked=true;
}
}

function ChangecheckboxStateToFalse(frmname)
{

var totalcheckvalus= document.getElementById(frmname);
for (var i =0; i < totalcheckvalus.elements.length; i++)
{
totalcheckvalus.elements[i].checked=false;
}
}
</script>


</head>
<body>
<form id="form1" runat="server">
<div id="div1" style="text-align: left">
<strong> Select and Select All Checkbox using
Java script</strong><table>
<tr>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox1" runat="server" /></td>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox4" runat="server" /></td>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox7" runat="server" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox2" runat="server" /></td>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox8" runat="server" /></td>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox6" runat="server" /></td>
</tr>
<tr>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox3" runat="server" /></td>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox9" runat="server" /></td>
<td style="width: 100px">
<asp:CheckBox ID="CheckBox5" runat="server" /></td>
</tr>
</table>
</div>
<asp:Button ID="Button1" OnClientClick ="ChangecheckboxStateToTrue('form1')" runat="server" Text="Select All" />
<asp:Button ID="Button2" OnClientClick ="ChangecheckboxStateToFalse('form1')" runat="server" Text="De Select All" />
</form>
</body>
</html>






Did you like this resource? Share it with your friends and show your love!


Responses to "How to select and unselect checkbox using Java script"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to pass Query String value from java script
    Previous Resource: Create Multiple calender control on runtime time
    Return to Resources
    Post New Resource
    Category: Javascript


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.