Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   checkbox and javascript (http://www.velocityreviews.com/forums/t89841-checkbox-and-javascript.html)

DotNetJunkies User 11-01-2004 11:02 AM

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.

=?Utf-8?B?S2FtYWwgVC4=?= 11-01-2004 03:25 PM

RE: checkbox and javascript
 
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.
>


bruce barker 11-01-2004 06:01 PM

Re: checkbox and javascript
 
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." <KamalT@discussions.microsoft.com> wrote in message
news:237053FE-8E60-4D94-9786-3D6EF975251E@microsoft.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.
> >




=?Utf-8?B?ZGVlcGFrIGt1bWFy?= 11-02-2004 02:41 AM

Re: checkbox and javascript
 
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." <KamalT@discussions.microsoft.com> wrote in message
> news:237053FE-8E60-4D94-9786-3D6EF975251E@microsoft.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.
> > >

>
>
>


=?Utf-8?B?ZGVlcGFrIGt1bWFy?= 11-02-2004 04:20 AM

Re: checkbox and javascript
 
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." <KamalT@discussions.microsoft.com> wrote in message
> > news:237053FE-8E60-4D94-9786-3D6EF975251E@microsoft.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.
> > > >

> >
> >
> >


=?Utf-8?B?S2FtYWwgVC4=?= 11-02-2004 04:54 AM

RE: checkbox and javascript
 
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.
> >



All times are GMT. The time now is 04:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.