473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

checkbox and javascript

1.
i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis....

2. after population there should be validation in checkboxlist.....
that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on the form.......

these 2 steps should be done in javascript only(no server side programming, i know it can be done easily)

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
Nov 18 '05 #1
5 3644
Hi,

Creating checkboxlist is very simple. All u need to do is give the same id
value for all the checkbox object.

For eg:

u have 3 checkbox and u wud like to create it as a checkboxlist,

<input type=checkbox id="chkList">CheckBox 1
<input type=checkbox id="chkList">CheckBox 2
<input type=checkbox id="chkList">CheckBox 3
The CheckBoxList is created. To access each checkbox object value, place the
following javacsript in inside ur <head> tag.

<script>
function getValues()
{
var checkBoxList = document.getElementById("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

Call this "getValues();" function onclick of a button.

<input type=button id="btn" onclick="getValues();">
Hope this code helps u........

Regards,
Kamal T.

"DotNetJunkies User" wrote:
1.
i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis....

2. after population there should be validation in checkboxlist.....
that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on the form.......

these 2 steps should be done in javascript only(no server side programming, i know it can be done easily)

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.

Nov 18 '05 #2
this code will not work. id's are supposed to be unique and getElementById
only returns the first match. you can switch to usings the name attribute
and getElementsByName it will work.

<input type=checkbox name="chkList">CheckBox 1
<input type=checkbox name="chkList">CheckBox 2
<input type=checkbox name="chkList">CheckBox 3

<script>
function getValues()
{
var checkBoxList = document.getElementsByName("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

-- bruce (sqlwork.com)

"Kamal T." <Ka****@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
Hi,

Creating checkboxlist is very simple. All u need to do is give the same id value for all the checkbox object.

For eg:

u have 3 checkbox and u wud like to create it as a checkboxlist,

<input type=checkbox id="chkList">CheckBox 1
<input type=checkbox id="chkList">CheckBox 2
<input type=checkbox id="chkList">CheckBox 3
The CheckBoxList is created. To access each checkbox object value, place the following javacsript in inside ur <head> tag.

<script>
function getValues()
{
var checkBoxList = document.getElementById("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

Call this "getValues();" function onclick of a button.

<input type=button id="btn" onclick="getValues();">
Hope this code helps u........

Regards,
Kamal T.

"DotNetJunkies User" wrote:
1.
i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should
be checked or unchecked on some condition basis....
2. after population there should be validation in checkboxlist.....
that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on
the form.......
these 2 steps should be done in javascript only(no server side programming, i know it can be done easily)
---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.

Nov 18 '05 #3
when i call the above fucntion on button's click event as follwoing
---------------------------------------------------------------------------------------------
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 104px; POSITION:
absolute; TOP: 80px" runat="server"
Text="Button" OnClick="getValues()">
----------------------------------------------------------------------------------------------
then error comes as -->
----------------------------------------------------------------------------------------------
Compiler Error Message: CS0117: 'ASP.WebForm1_aspx' does not contain a
definition for 'getValues'

----------------------------------------------------------------------------------------------
apart from this , i need that if user click on button without checking any
one of them(i.e.at least one checkbox should be checked or selected by him
before he submits page to server otherwise alert message should come that
"plz check any one of them or select all of them" i.e. this problem is
something related to validation
"bruce barker" wrote:
this code will not work. id's are supposed to be unique and getElementById
only returns the first match. you can switch to usings the name attribute
and getElementsByName it will work.

<input type=checkbox name="chkList">CheckBox 1
<input type=checkbox name="chkList">CheckBox 2
<input type=checkbox name="chkList">CheckBox 3

<script>
function getValues()
{
var checkBoxList = document.getElementsByName("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

-- bruce (sqlwork.com)

"Kamal T." <Ka****@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
Hi,

Creating checkboxlist is very simple. All u need to do is give the same

id
value for all the checkbox object.

For eg:

u have 3 checkbox and u wud like to create it as a checkboxlist,

<input type=checkbox id="chkList">CheckBox 1
<input type=checkbox id="chkList">CheckBox 2
<input type=checkbox id="chkList">CheckBox 3
The CheckBoxList is created. To access each checkbox object value, place

the
following javacsript in inside ur <head> tag.

<script>
function getValues()
{
var checkBoxList = document.getElementById("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

Call this "getValues();" function onclick of a button.

<input type=button id="btn" onclick="getValues();">
Hope this code helps u........

Regards,
Kamal T.

"DotNetJunkies User" wrote:
1.
i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should
be checked or unchecked on some condition basis....
2. after population there should be validation in checkboxlist.....
that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on
the form.......
these 2 steps should be done in javascript only(no server side programming, i know it can be done easily)
---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.


Nov 18 '05 #4
ya Kamal, and Bruce ... my coe is working fine and done some modifcations in
both of urs code according to my need.. my code is following
........................
-------------------------------------------------------------------------------------------------
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="thirdpro.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language="javascript">
function getValues()
{
var checkBoxList1 = document.getElementById("chkList1");
var checkBoxList2 = document.getElementById("chkList2");
var checkBoxList3 = document.getElementById("chkList3");

if ((checkBoxList1.checked != true) && (checkBoxList2.checked != true) &&
(checkBoxList3.checked != true))
{
alert('Plz Select At Least One Value....');
}
else
{
alert('Crawling Processing....');
}
}

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<input id="chkList1" type="checkbox" >CheckBox1
<input id="chkList2" type="checkbox" >CheckBox1
<input id="chkList3" type="checkbox" >CheckBox1
<input id="btn" value="Set Crawl" style="Z-INDEX: 101; LEFT: 40px;
WIDTH: 80px; POSITION: absolute; TOP: 192px; HEIGHT: 24px"
onclick="getValues()" type="button">
</form>
</body>
</HTML
-------------------------------------------------------------------------------------------------
thanks a lot for helping me ......bruce how can i become MVP (is there any
paper of microsoft for this or any other way...tell me and guide me
plz..kamal thanks ..u seems to be indian ..i m 26/m/delhi/ working in C# in a
firm whoch is not a S/W development .. im working in a team of only 3 people
so i will need urs help time to time .thanks a lot......once again..see u
soon with new probelm bye )

"deepak kumar" wrote:
when i call the above fucntion on button's click event as follwoing
---------------------------------------------------------------------------------------------
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 104px; POSITION:
absolute; TOP: 80px" runat="server"
Text="Button" OnClick="getValues()">
----------------------------------------------------------------------------------------------
then error comes as -->
----------------------------------------------------------------------------------------------
Compiler Error Message: CS0117: 'ASP.WebForm1_aspx' does not contain a
definition for 'getValues'

----------------------------------------------------------------------------------------------
apart from this , i need that if user click on button without checking any
one of them(i.e.at least one checkbox should be checked or selected by him
before he submits page to server otherwise alert message should come that
"plz check any one of them or select all of them" i.e. this problem is
something related to validation
"bruce barker" wrote:
this code will not work. id's are supposed to be unique and getElementById
only returns the first match. you can switch to usings the name attribute
and getElementsByName it will work.

<input type=checkbox name="chkList">CheckBox 1
<input type=checkbox name="chkList">CheckBox 2
<input type=checkbox name="chkList">CheckBox 3

<script>
function getValues()
{
var checkBoxList = document.getElementsByName("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

-- bruce (sqlwork.com)

"Kamal T." <Ka****@discussions.microsoft.com> wrote in message
news:23**********************************@microsof t.com...
Hi,

Creating checkboxlist is very simple. All u need to do is give the same

id
value for all the checkbox object.

For eg:

u have 3 checkbox and u wud like to create it as a checkboxlist,

<input type=checkbox id="chkList">CheckBox 1
<input type=checkbox id="chkList">CheckBox 2
<input type=checkbox id="chkList">CheckBox 3
The CheckBoxList is created. To access each checkbox object value, place

the
following javacsript in inside ur <head> tag.

<script>
function getValues()
{
var checkBoxList = document.getElementById("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

Call this "getValues();" function onclick of a button.

<input type=button id="btn" onclick="getValues();">
Hope this code helps u........

Regards,
Kamal T.

"DotNetJunkies User" wrote:

> 1.
> i want to populate checkboxlist using javascript only at client

side ....how can i do this..by populate word i mean that checkboxes should
be checked or unchecked on some condition basis....
>
> 2. after population there should be validation in checkboxlist.....
> that is if user clicks a button wihout checking any one of

them(i.e. at least one shuld be checked) ... alerat message shouls come on
the form.......
>
> these 2 steps should be done in javascript only(no server side

programming, i know it can be done easily)
>
> ---
> Posted using Wimdows.net NntpNews Component -
>
> Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup

engine supports Post Alerts, Ratings, and Searching.
>


Nov 18 '05 #5
bruce is right...... it shld. be name attribute instead of id

"Kamal T." wrote:
Hi,

Creating checkboxlist is very simple. All u need to do is give the same id
value for all the checkbox object.

For eg:

u have 3 checkbox and u wud like to create it as a checkboxlist,

<input type=checkbox id="chkList">CheckBox 1
<input type=checkbox id="chkList">CheckBox 2
<input type=checkbox id="chkList">CheckBox 3
The CheckBoxList is created. To access each checkbox object value, place the
following javacsript in inside ur <head> tag.

<script>
function getValues()
{
var checkBoxList = document.getElementById("chkList");

for(i=0;i<checkBoxList.length;i++)
{
if (checkBoxList [i].checked == true)
{
alert('CheckBox ' + i + ' is checked ')
}
}
}
</script>

Call this "getValues();" function onclick of a button.

<input type=button id="btn" onclick="getValues();">
Hope this code helps u........

Regards,
Kamal T.

"DotNetJunkies User" wrote:
1.
i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis....

2. after population there should be validation in checkboxlist.....
that is if user clicks a button wihout checking any one of them(i.e. at least one shuld be checked) ... alerat message shouls come on the form.......

these 2 steps should be done in javascript only(no server side programming, i know it can be done easily)

---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
5
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add...
2
by: UJ | last post by:
Is there a way with a asp:checkbox to run a JavaScript to display/hide text/input on the screen without doing a postback? I also need to be able to access the stuff at the server so I need to...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
1
by: pleaseexplaintome | last post by:
I have a datagrid with checkboxes and I can check/uncheck the checkboxes to update a database by calling my oncheckchanged function. I would like to add popup asking the users if they are sure...
10
by: rn5a | last post by:
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....
4
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.