473,488 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Radio button de-check with onclick?

I have a radio button group. When the page loads none of them are
selected. OnClick selects ONE and clicking another one selects a
different one - this is normal behavior.

I want to modify it so that clicking on a radio which is already
selected will deselect it so that none of the group are selected.

I can get the required behavior with a double-click:

ondblclick="this.checked=!(this.checked);"

or even:

ondblclick="this.checked=false;"

How can I get that behavior with an onclick() - to de-check the
currently checked button?
Oct 29 '06 #1
3 5808
Harry Haller wrote:
I have a radio button group. When the page loads none of them are
selected. OnClick selects ONE and clicking another one selects a
different one - this is normal behavior.

I want to modify it so that clicking on a radio which is already
selected will deselect it so that none of the group are selected.

I can get the required behavior with a double-click:

ondblclick="this.checked=!(this.checked);"

or even:

ondblclick="this.checked=false;"

How can I get that behavior with an onclick() - to de-check the
currently checked button?
You are asking how to change a radio button to behave like a checkbox.
This isn't a good idea as that is not what people's mental model of
radio button behavior is. Please consider adding one more radio
button with a label of 'None' or something similar. You can even
default it as 'checked'. This allows the user to select a radio button
from the group while still allowing them to indicate that it was a
mistake and choose 'nothing'.

John

Oct 29 '06 #2
On 29 Oct 2006 14:02:01 -0800, "johkar" <no********@msn.comwrote:
>Harry Haller wrote:
>I have a radio button group. When the page loads none of them are
selected. OnClick selects ONE and clicking another one selects a
different one - this is normal behavior.

I want to modify it so that clicking on a radio which is already
selected will deselect it so that none of the group are selected.

I can get the required behavior with a double-click:

ondblclick="this.checked=!(this.checked);"

or even:

ondblclick="this.checked=false;"

How can I get that behavior with an onclick() - to de-check the
currently checked button?

You are asking how to change a radio button to behave like a checkbox.
This isn't a good idea as that is not what people's mental model of
radio button behavior is. Please consider adding one more radio
button with a label of 'None' or something similar. You can even
default it as 'checked'. This allows the user to select a radio button
from the group while still allowing them to indicate that it was a
mistake and choose 'nothing'.

John
My sentiments too. But I code the site - I don't write the spec. My
manager does and he hasn't read books on "Designing the user
interface", etc. ... He is very hands on - doesn't like me taking the
laptop home, wants me to work exclusively from the office. The
previous designer wrote the pages like that - right now WHEN NOTHING
IS SELECTED - the system logically selects everything in that group -
so when no radio is selected - all 6 of them must be selected in the
form.

I agree with you - it should be a checkbox group with either all or
only 1 selected!

But..., out of interest - how do I go about modifying the click
button? - can I override the event or add a supplementary event
handler?

I will tell the boss (again) what I think the page should be doing.
Oct 30 '06 #3

Harry Haller написав:
I have a radio button group. When the page loads none of them are
selected. OnClick selects ONE and clicking another one selects a
different one - this is normal behavior.

I want to modify it so that clicking on a radio which is already
selected will deselect it so that none of the group are selected.

Try this, maybe you will satisfy your manager :)

<html>
<head>
<script type="text/javascript">

function cl(sender)
{
if (sender.alreadyChecked)
sender.checked = false;
}

function md(sender)
{
sender.alreadyChecked = sender.checked;
}

</script>
</head>
<body>
<input type="radio" value="1" name="test" onmousedown="md(this)"
onclick="cl(this)">
<input type="radio" value="2" name="test" onmousedown="md(this)"
onclick="cl(this)">
<input type="radio" value="3" name="test" onmousedown="md(this)"
onclick="cl(this)">
</body>
</html>

Oct 30 '06 #4

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

Similar topics

3
3871
by: M.E. | last post by:
Hi I have 4 radio buttons. each button to determine which page to go to. But before page open user enters username in a text box. So when submitted, Page opens relevant to that user displaying...
2
7529
by: Renie83 | last post by:
Hi all! I was wondering does anyone have any ideas on how I can send info to a SQL database by choosing a radio button. What I want to do is set one radio button to "Max" and one to type "Avg"....
3
43953
by: NONYA | last post by:
This is driving me crazy. I'm having trouble with how a simple radio button is displayed, in a simple html form. The default has the outline around the radio button shaded gray only in the top...
0
329
by: Jane | last post by:
Hello I am developing a windows application, which uses a group of radio buttons and other components. After data is loaded from database, a user can select another radio button which has larger...
1
6886
by: Rick | last post by:
After being frustrated with this issue on several occasions I think I found the secret sauce for solving the issue after reading a few different messages about what others thought and trying a...
3
1769
by: Dot net work | last post by:
Is it possible to have a radiobuttonlist control appear on a webform without any radio buttons checked to begin with? I would really like to make sure that the user specifically chooses a radio...
1
2538
by: Shane | last post by:
I think that I found a bug in the Radio Button, and I wanted to give everybody a "Heads Up". I spent three days doing trial and error until I found a work around. I created a user control with a...
5
2700
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button...
3
2832
by: jahphill | last post by:
Hey. I thought id make a seperate discusion because the other became a bit lengthy and confusing. Aim: Create a php file which works with the script below, which makes the radiobuttons work =D...
0
2282
by: jehugaleahsa | last post by:
Hello: I have radio buttons bound to boolean properties in a business object. private void bindRadioButton(RadioButton button, string propertyName) { Binding binding =...
0
7108
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
6967
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
7142
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
6847
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
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3078
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
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.