Changing the backcolor once i check the checkbox in checkbox list using javascript

Hi Friends,

My requirement is Listbox with checkbox

I have taken one div tag make it as overlap.in tat div tag i hav taken one checkboxlist..

Now it looks like a listbox with checkox.

Data is binded properly.once i check the checkbox in checkboxlist  i need to change tat checkbox row color using javascript .

Please can u give some suggestions

Thanks

sandhya

 

0
sandhyabhavani
7/2/2008 10:58:32 AM
asp.net.client-side 24353 articles. 1 followers. Follow

3 Replies
625 Views

Similar Articles

[PageSpeed] 48

0
vik20000in
7/2/2008 11:46:14 AM

Try this:

<form id="form1" runat="server">
 <asp:CheckBoxList id="CheckBoxList1" onclick="checkBoxList1OnCheck(this);" runat="server">
  <asp:listitem value="1">Item 1</asp:listitem>
  <asp:listitem value="2">Item 2</asp:listitem>
  <asp:listitem value="3">Item 3</asp:listitem>
 </asp:CheckBoxList>
</form>

<script type="text/javascript">
function checkBoxList1OnCheck(listControlRef)
{
 var inputItemArray = listControlRef.getElementsByTagName('input');

 for (var i=0; i<inputItemArray.length; i++)
 {
  var inputItem = inputItemArray[i];

  if ( inputItem.checked )
  {
   inputItem.parentElement.style.backgroundColor = 'Red';
  }
  else
  {
   inputItem.parentElement.style.backgroundColor = 'White';
  }
 }
}
</script>

Note that I attached the event handler in the HTML, which works, but the correct way in ASP.NET is to do this in the CodeBehind Page_Load event handler like this:
     CheckBoxList1.Attributes.Add("onclick", "checkBoxList1OnCheck(this);");

Of course, remove it from the HTML.

NC...

0
NC01
7/2/2008 11:55:01 AM

One simple hint to access the style from Javascript is.

When u find "-" in css property then it's access by javascript by removing "-" and then making the immediate character in UpperCase. like

CSS: background-color ---> Javascript: backgroundColor

document.getElementById('<ele>').style.backgroundColor

I hope this will help u in future.


Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
Ahmedabad
0
Coool
7/2/2008 12:26:32 PM
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"...

Checkbox List Check/Uncheck All Client Side
I have developed several web forms that include checkbox lists and radiobutton lists whose text and value fields are generated from a SQL Database table. I now would like to create a button or checkbox that will select and deselect the checkboxes on the client side. I have looked into the scripts that cycle through individual checkboxes and change their selected value based on their name, but the problem there is that checkbox lists automatically create individual names for each checkbox in the list - for example: I have a checkbox list with ID="cbxCardio" The names generated f...

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...

Change a label backcolor using client-side javascripting
I'm working on a small project where I need to either change the backcolor of a label or change the image on the page. The user will have a list of colors in a dropdown to pick from. I've tried many variations of the code below and nothing seems to have any effect on the label backcolor. Here's what I have: <script type="text/javascript">function Color(elem) {var indx = elem.selectedIndex; var lbl = document.getElementById('<%= label1.ClientID %>');if(indx == null) alert('d_Color not found!'); else {if(indx == 1) lbl.backColor = ...

Checking All CheckBoxes in a GridView Using Client-Side Script
Hi; I have  checkbox column in gridview and a checkbox in header gridview. i write down code: Dim checkbox As CheckBox = GridView2.HeaderRow.FindControl("HeaderCheckbox")checkbox.Attributes("onclick") = "ChangeAllCheckBoxStates(this.checked);"  For Each row As GridViewRow In GridView2.Rows Dim a As CheckBox = row.Cells(0).FindControl("CheckBox2") If row.RowType = DataControlRowType.DataRow ThenClientScript.RegisterArrayDeclaration("CheckboxIDs", String.Concat("'", a.ClientID, "'")) End IfNe...

checkbox client side onclick event to manage checked status of multiple checkbox controls or multiple items in a checkboxlist
I want to use javascript to run a client side function to manage the checked state of multiple checkbox controls.  For example, if checkboxA is checked by the user, I want to uncheck checkboxB & checkboxC and check checkboxD.  I do not want to make this a postback event. Also, I'm considering using a checkboxlist control.  If I were to use a checkboxlist control with 6 list items, how would I control the checked status of the different list items based upon an onclick event for one of the list items.  An example: if checkbox list item (1) is checked, I want to unc...

Can't find CheckBox.Checked client-side changes until PostBack
I've got a Placeholder on a page. Within this page's Page_Load method, I create a TemplateColumn containing a Checkbox, add that TemplateColulmn to the DataGrid, and then add the DataGrid to the Placeholder. Upon postback, I follow the same steps to create the DataGrid. Any client-side changes I make to any of the CheckBoxes within the DataGrid are not reflected after adding the DataGrid in Page_Load. The CheckBoxes do reflect client-side changes in any PostBack event handlers I have on the page. Does anyone have an idea why these Checkboxes do not reflect client-side changes until ...

Changing properties of single CheckBox in a CheckBox List
According to Microsoft this cannot be done, but I am looking for some type of a hack or something.  I have a CheckBoxList control on an aspx page and I need to be able to highlight the CheckBox and text for a particular checkbox within the list.  The CheckBox is bound to a Dataset that populates the List, and I can access the individual values of each CheckBox in the CheckBoxList, but I cannot programmatically change the properties for just a single CheckBox without it taking affect on the entire List.  Does anyone know how this can be accomplished.  I have searched th...

A checkbox that checks the other checkboxes...
Hi everyone, I'd like to create a checkbox that checks all the checkboxes that are contained in my repeater. Does anyone know how to do this ??? I've tried some javascripts found on the net but nothing works... :'( Please help me ! It's rather urgent ! Thanks for answering ! ^^ Hello... I don't know how to make the page react when you check the box (actually I'm having trouble doing so with a dropdownlist, so if you have any idea :p) but if you add a button that you click after checking the box, you can add in the code behind file [ CheckBox1.Checked = true ] and do so to all t...

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...

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

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...

using Javascript to check a checkbox?
I need to check a checkbox server control using javascript when a button is clicked and yes it does have to be done in Javascript. Anyone know the syntax? thanx weisenbr You can write like this in the onclick function of the button: checks = document.getElementsByTagName("input") for (i=1;i<=checks.length;i++) { if (checks[i-1].type == "checkbox") { if ( checks[i-1].checked) { // put your logic here ...

how do i get selectedValue of drop down list server side if i am populating it using client side javascript?
 Hi All.I am populating a drop down list client side using: The drop down list is populated based on a selection of another drop down list. ddlList.options[i] = new Option(1,2); as an exampleThe populating is done as i need it to. However, a button click event i am trying to get the selectedValue of the ddlList. However, it doesn't give me it. It only gives me the selectedValue of the drop down list on first rendering. Any ideas on how i can get it?   Could You paste some code? That would be helpful. Thanks S@ss (Shashi Shekhar Singh)My BlogPlease mark a post as ANSWER ...

Web resources about - Changing the backcolor once i check the checkbox in checkbox list using javascript - 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! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

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
The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

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: 1/16/2016 1:56:05 PM