473,513 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CheckBox selection

Hi,

I have a 5 checkboxes and I would like to be able to use them as grouped
radiobuttons or a checkboxlist (one selection at the time) in the client side
without having to use a autopostback.
I think the only way is javascript but I don't know how. does any one have a
sample code to do that?
Cheers

Feb 20 '07 #1
3 2478
Hi,

Badis wrote:
Hi,

I have a 5 checkboxes and I would like to be able to use them as grouped
radiobuttons or a checkboxlist (one selection at the time) in the client side
without having to use a autopostback.
I think the only way is javascript but I don't know how. does any one have a
sample code to do that?
Cheers
I would recommend against that, because checkboxes are not destined to
behave like radiobuttons, it's confusing the user and is bad ergonomy.

That said, you can programatically check or uncheck a checkbox in
JavaScript using this code:

// The checkbox's ID is myCheckbox1
var cb = document.getElementById( "myCheckbox1" );

if ( cb != null
&& cb.checked != null )
{
cb.checked = true; // or false
}

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 20 '07 #2
Yes, but I could find any OnClient event for checkboxes to call this
javascript code and I tried to run it in "OnCheckedChanged" but it looks that
this event needs the autopostback turned on!!!?
sorry, i'm a beginner in asp but how can I run this code to be executed in
client side

"Laurent Bugnion [MVP]" wrote:
Hi,

Badis wrote:
Hi,

I have a 5 checkboxes and I would like to be able to use them as grouped
radiobuttons or a checkboxlist (one selection at the time) in the client side
without having to use a autopostback.
I think the only way is javascript but I don't know how. does any one have a
sample code to do that?
Cheers

I would recommend against that, because checkboxes are not destined to
behave like radiobuttons, it's confusing the user and is bad ergonomy.

That said, you can programatically check or uncheck a checkbox in
JavaScript using this code:

// The checkbox's ID is myCheckbox1
var cb = document.getElementById( "myCheckbox1" );

if ( cb != null
&& cb.checked != null )
{
cb.checked = true; // or false
}

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 20 '07 #3
Hi,

Badis wrote:
Yes, but I could find any OnClient event for checkboxes to call this
javascript code and I tried to run it in "OnCheckedChanged" but it looks that
this event needs the autopostback turned on!!!?
sorry, i'm a beginner in asp but how can I run this code to be executed in
client side
First you need to understand what is running on the client (JavaScript)
and what runs on the server (C#, VB.NET). The events you set in C# code
will be executed on the server, so of course it needs a postback.

Events exist in JavaScript too, however the syntax is different.

For example:

<input type="checkbox" onclick="doSomething();" />

HTH,
Laurent
>
"Laurent Bugnion [MVP]" wrote:
>Hi,

Badis wrote:
>>Hi,

I have a 5 checkboxes and I would like to be able to use them as grouped
radiobuttons or a checkboxlist (one selection at the time) in the client side
without having to use a autopostback.
I think the only way is javascript but I don't know how. does any one have a
sample code to do that?
Cheers
I would recommend against that, because checkboxes are not destined to
behave like radiobuttons, it's confusing the user and is bad ergonomy.

That said, you can programatically check or uncheck a checkbox in
JavaScript using this code:

// The checkbox's ID is myCheckbox1
var cb = document.getElementById( "myCheckbox1" );

if ( cb != null
&& cb.checked != null )
{
cb.checked = true; // or false
}

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 21 '07 #4

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

Similar topics

0
2113
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...
1
1863
by: thejackofall | last post by:
Hi. I have a checkbox column in my datagrid like this: <Columns> <asp:TemplateColumn HeaderText=" "> <ItemTemplate> <asp:CheckBox ID='Selection' runat="server"></asp:CheckBox> <asp:Label...
4
4454
by: Nicolas Rubin | last post by:
Hi, I would transfer the result of a checkbox selection into an SQL request. Could you help me ? Many thanks in advance Nicolas
2
5435
by: Andre Ranieri | last post by:
Hi folks, I have a datagrid which contains a template item checkbox column. I've included a checkbox as a HeaderTemplate item which fires a server-side function to check or uncheck all the...
1
1402
by: puja | last post by:
hi all, I have a form which has checkbox list which has items as below 1) Input 1 2) Input 2 3) Input 3 4) Input 4 5) Input 5
1
1785
by: Joja | last post by:
I have 3 checkboxes but the user should select just one. How to block multiple checkbox selection ? Joja
3
6722
by: delram | last post by:
I'm trying to get user selections (using checkboxes) on one JSP page(A.jsp) and pass them on to another page. So I have one page with a list of dynamically populated items like this 1 2 ...
0
3013
by: New2ASP | last post by:
Thanks everyone in advance for your help. I am fairly new to web development but an experienced window-based developer. Here's the structure of my Gridview Column 1 : Checkbox with SelectAll...
3
3666
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.