473,730 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ 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="thi s.checked=!(thi s.checked);"

or even:

ondblclick="thi s.checked=false ;"

How can I get that behavior with an onclick() - to de-check the
currently checked button?
Oct 29 '06 #1
3 5845
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="thi s.checked=!(thi s.checked);"

or even:

ondblclick="thi s.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="th is.checked=!(th is.checked);"

or even:

ondblclick="th is.checked=fals e;"

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.already Checked)
sender.checked = false;
}

function md(sender)
{
sender.alreadyC hecked = sender.checked;
}

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

Oct 30 '06 #4

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

Similar topics

3
3884
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 selected page. I have no idea how to achieve this, and a good example would be greatly appreciated.
2
7540
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". When a user clicks on a radio button I want the value of whatever button was chosen to be placed inside the "type" field in my database after they hit submit. Also, if anyone knows of the best sites or books I can use about VBScript or ASP please...
3
43976
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 left hand side corner and on a white background it doesn't show up very well. I've seen multiple examples of radio buttons that are fully outlined in blue and the little dot is green. How the heck do I do this??? I've figured out how to change...
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 TabIndex, But he can't select another radio button which has smaller TabIndex in the group. For example, when a form is loaded and the TabIndex of selected radio button is 1. If a user selected another radio button that TabIndex is 0, then the...
1
6938
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 combination of them all. What worked for me was the following: 1. Put a Break Point in MFC source file DLGDATA.CPP on line 338 which is: TRACE0("Warning: skipping non-radio button in group.\n"); (Copyright
3
1787
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 button choice, rather than just accept the default value, which is the first radio button in the list being checked. TIA, -dnw.
1
2555
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 text box and two radio buttons. The text box has the TabStop = True, and both radio buttons have TabStop = False. The radio buttons are set to false so that a Tab (or captured Enter) may tab to the next control. The appropriate radio button is...
5
2724
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 are selected it should giv message dat select a radio button. else it should go to other page. My code works fine when there are more than 1 radio button but when only 1 radio button is der dat time it does not work
3
2846
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 Right, when say mp3 radio button is selected, and say BLA is typed in the text box. I would like it to open up...
0
2296
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 = button.DataBindings.Add("Checked", exclusionBindingSource, propertyName,
0
9440
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9299
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9227
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6029
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4800
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2174
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.