Javascript validation on gridviev for checking wheter any of the checkbox is checked or not

Hi guys!

I have gridview with checkboxes.

 I have calculate button outside gridview. This calculate button do some calculations depending on the row selected by checking checkbox

Now on onClientClick event of calculate button i want to call javascript which will show alert message if none of the row is selected by checking checkbox.

how to achieve  this......

Any help will be appreciated.

 

Thank you


sarvesh
0
sarvesh1
4/14/2009 6:23:08 AM
asp.net.client-side 24353 articles. 1 followers. Follow

3 Replies
588 Views

Similar Articles

[PageSpeed] 58

button OnClientClick = "return ValidateCheckBox();"

function ValidateCheckBox()

{

var allChkBox   = document.getElementsByTagName('input');

var checked = false;

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

{

if(allChkBox[i].type=='checkbox')

{

 if(allChkBox[i].checked)

checked=true;

}

}

if(!checked)

{

alert('plz select at least one checkbox') ;

}

}


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
4/14/2009 10:08:40 AM

Please have  look on following function 

function dojob() {
            var allowAdd = 0; var noofgridcolums = 8;


            var grid = document.getElementById("<%=grvModule.ClientID%>");
            var cell;
            if (grid.rows.length > 0) {
                for (i = 1; i < grid.rows.length; i++) {
                    for (k = 0; k < noofgridcolums; k++) {
                        cell = grid.rows[i].cells[k];
                        for (j = 0; j < cell.childNodes.length; j++) {
                            if (cell.childNodes[j].type == "checkbox") {
                                if (cell.childNodes[j].checked)
                                    allowAdd = allowAdd  + 1;
                            }
                        }
                    }
                }
            }

0
alankarp
4/14/2009 11:04:11 AM

Try this:

<asp:button id="submitButton" runat="server" text="Submit" OnClientClick="return validateCheckBoxes();"></asp:button>

<script type="text/javascript">
<!--
function validateCheckBoxes()
{
 var gridRef = document.getElementById('<%= GridView1.ClientID %>');
 var inputElementArray = gridRef.getElementsByTagName('input');
 var isChecked = false;

 for (var i=0; i<inputElementArray.length; i++)
 {
  var inputElement = inputElementArray[i];

  if ( (inputElement.type == 'checkbox') && (inputElement.checked) )
  {
   isChecked = true;
   break;
  }
 }

 if ( isChecked == false )
 {
  alert('You must select at least one CheckBox');
  return false;
 }

 return true;
}
// -->
</script>

NC...

0
NC01
4/14/2009 11:39:21 AM
Reply:

Similar Artilces:

checking checkbox is checked or not using checkbox.checked
Hi,my checkbox is<asp:CheckBox ID="Chkcity" runat="server" Text="My own city"  OnCheckedChanged="EventHandler"/>code behind: Private Sub Chkcity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkcity.CheckedChangedif (Chkcity ...............)end if End SubERROR    'EventHandler' is not a member of 'ASP.bpoaddjob_aspx'.    Please Mark the post as "ANSWER" if it helps you I think it should be like this:<asp:CheckBox ID="Chkcity"...

Validation to Check if checkbox is checked
Hi,Which Validation statement should i use to check whether a checkbox is checked?Thanks You can also use CustomValidator for validate if check box is checked or not. Here is the example:   <script> function checkTemp() {             if (document.getElementById("valcheckBoxTemp").checked)                         args.IsValid = true;             else ...

javascript: check all check box in a perticular row , when i check a checkbox i that perticuler row
Hi Friends,I have a gridview. and I am having checkboxes in all the columns and all the rows. Like it is about selecting subjects.My Problem is when I select a Checkbox in First column of any row, all the checkboxes in that particular row should also be selected.How can I do this... . I have done all checkboxes checked for column, but no idea about row.Please guide.Thanks. Hi, this can be done with the help of jQuery, a great & free javascript library. Take a look at this article: Check All Checkboxes in GridView using JQuery. Grz, Kris.Read my blog. Handy Firefox plugins for web dev...

how to check if a checkbox is checked using javascript.
Hi all, I am new to asp.net and trying to learn it, I have created a simple page including a button and a checkboxes.  Now, I want that when I check the checkbox, it should display a message. but it is gving some errors like 1. ) expected 2. Invalid expresson term ':' 3. ; expexcted  4. Invalid expresson term ':'  my sample coding is as follows   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trans...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

.net validators + client-side javascript validation, EnableEventValidation=false
Scenario: 1. I have a DropDownList, with 2 listitems in the .aspx. appenddatabound=true and it is tied to a datasource (via datasourceid), autopostback=false, onchange=checkIfAddNew(this) [this is the client side onchange event]The second option on this dropdown is "Add New", and the checkIfAddNew function pops up a new window and when it returns, it adds the newly created option to the dropdown. In order for this to happen without asp.net getting mad, EnableEventValidation has to be set to false in the Page directive. In addition to this dropdownlist, there is a RequiredFieldValidator...

Can we check validation both on client side & server side?
 Hi All, Can we check validation both on client side & server side?Thanks & RegardsNeeraj  Yes, the standard asp.net validation controls already do this.Before you process any code on the server side that should have passed through validation you need to check Page.IsValid = trueThis will also catch the situation where the user has javascript disabled. yes you can check validation both the side as per your requirement.Most advantage is that if some user set the JavaScript Enabled False in the Browser settings at that time we don't worry about any validat...

Javascript function to check whether checkbox is checked or not
I have 2 check boxes on my form and would like to do create javascript function to check which checkbox is clicked and whether its checked or unchecked. I am using master page also so unable to do like this:- if(document.theForm.CheckBox1.checked==false) { //Some processing }RegardsGaurav Kumar You can do this with your javascript, it is better than document.theForm.CheckBox1... because it adheres to the w3c standards. The reason that document.theForm.CheckBox1... will not work is because when you use a master page, you do not place you cannot create a form to place your code in. ...

Check One CheckBox To Check All CheckBoxes
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named CheckAllRows on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside within the ItemTemplate of the same TemplateColumn. This is the code (the ID of the CheckBox in the Header...

Q check the client side validation befor activate servers side
hello i have aspx file with textbox serverside to fiil and clientside validators i wont when pressing buttun sendmail to check via client side if all the validators(all microsoft validators) are pass ok if not then go to the place where is the errow and after validating to go to serverside method that send the mail(wriiten) thens  why do you need to do the validation client side?all you need to do is wrap this around the code that sends the email.  If page.IsValid then' code that sends the mailEnd ifI believe in c# it would be if (page.IsValid) { //code to ...

Checkbox checked at client side???
Hi, I have a datagrid. In this datagrid At each row I have a checkbox to select the whole row. The second column is a bound column and it keeps the id of the product, the third contains the name of the product and so on... I want to get the id of the product as soon as i check the checkbox. However,this should be handled in client side. Can anyone help me? Thanks... Implement the ItemDataBound event of the grid and make sure ID of the row gets passed to the client side onclick event handler of the checkbox.Bug [MCSD] I'm sorry but I could not manage to implement ItemDataB...

How to check for the existing user in database and using custom validator how to check check box is checked or not?
Hi Friends, For Registration page i want to check if that user already exist in database or not? and i also have to check if user have check the checkbox for i agree then only he will be able to complete registration. here i am sending my design. and all validation i have done all validation except these two.<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PRIZE MLS</title><link href="css/style.c...

Check file type with custom validator. Try to write client-side validation function.
 I've written simple code to validate type of uploaded file. I allow only to upload gif file. Here's aspx code: <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="FileUpload1" Display="Dynamic" ErrorMessage="CustomValidator" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator><br /> <asp:Label ID="Label1" runat="server" Text...

Checked=Checked
 I am dynamically writing out checkboxes on a page.  I have 2 link buttons on the page that sets a boolean variable to True or False. This boolen is set in Page_PreInit and is used to Select or Deselect all the Checkboxes as they are written out. A Select ALL, Deselect ALL type of thing. At least that is the plan. As the page is being written out I do this for each checkbox and then add it to a table cell control that it added to a table row and on. tc is the table cell.  Dim chkItem As CheckBox = New CheckBox chkItem.ID = "chkRecommend" + drMember("ID")...

Web resources about - Javascript validation on gridviev for checking wheter any of the checkbox is checked or not - asp.net.client-side

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: jobs@sometrics.com Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 12/8/2015 9:55:46 AM