473,387 Members | 1,569 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,387 software developers and data experts.

Dumb question that I'm struggling with

I have a radio button, and I would like to use JS to allow it to be
unselected when you click an already selected radio button. I thought
this would be really simple. Here is what I'm doing:

<input type="radio" value="temporary" id="radioTemporary"
name="redirectType" onclick="if(this.checked==true){this.checked=false ;
}" />

I expected this to uncheck the radio button if it was clicked when
already checked. However, it effectively prevents it from being
selected. Any help?

-Josh

Jul 23 '05 #1
2 984


jb****@heraldic.us wrote:
I have a radio button, and I would like to use JS to allow it to be
unselected when you click an already selected radio button. I thought
this would be really simple. Here is what I'm doing:

<input type="radio" value="temporary" id="radioTemporary"
name="redirectType" onclick="if(this.checked==true){this.checked=false ;
}" />

I expected this to uncheck the radio button if it was clicked when
already checked. However, it effectively prevents it from being
selected. Any help?


You could try
<input type="radio"
onclick="if (this.checked) {
this.checked = false;
if (event.preventDefault) {
event.preventDefault();
}
return false;
}
else {
return true;
}"
but I haven't tested that and I am afraid you might get different
results in different browsers as manipulating the checked property in an
onclick handler is tricky. And changing the behavior of standard
controls is usually not a good idea as it is going to confuse users.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Hi Josh

try this, it works for me

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>

<script type="text/javascript">

function on_off(me)
{

if(me.value=='off'){me.checked=true;me.value='on'} else{me.checked=false;me.v
alue='off'};
alert(me.checked);
}
</script>
</head>

<body>
<input type="radio" value="off" id="radioTemporary" name="redirectType"
onclick="on_off(this)" />
</body>
</html>

Chris
<jb****@heraldic.us> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have a radio button, and I would like to use JS to allow it to be
unselected when you click an already selected radio button. I thought
this would be really simple. Here is what I'm doing:

<input type="radio" value="temporary" id="radioTemporary"
name="redirectType" onclick="if(this.checked==true){this.checked=false ;
}" />

I expected this to uncheck the radio button if it was clicked when
already checked. However, it effectively prevents it from being
selected. Any help?

-Josh

Jul 23 '05 #3

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

Similar topics

16
by: squash | last post by:
a dumb question i had on my mind: Say you have a dynamically created web page . Isn't it more secure to write it in php since a visitor will not be able to tell it is dynamically created? But...
0
by: Duncan Mole | last post by:
Hi, I know this is dumb but if I add a reference to the release version of a company class library in debug and build it it works fine. If I then switch to release and rebuild the reference is...
4
by: David | last post by:
Hi Everybody - After a couple of brain-wracking weeks, I have begun designing my first DB. I am struggling, but determined to make this work. Would any of you be willing to take a glance at my...
26
by: dagger | last post by:
Hi there. I'm using C under FreeBSD with the gcc compiler and am having a bit of trouble using the calloc and realloc calls. As an example the code snippet: #include <stdio.h> int main() {...
2
by: Bill Nguyen | last post by:
I would like to add a new VB.NET project using the same folder being used by another project so that I can share several forms already creaded by the other project. However, .NET created a new...
16
by: CMM | last post by:
Is it me or has anyone noticed that F1 is really dumb in VS2005. Since VB3 I have been able to click F1 on an ambiguous method in code and the IDE automatically determines the type based on the...
2
by: mjeaves | last post by:
Hello there, Hope someone can help. I have data arriving in a table, a Cron job is triggered when the data arrives. ---- table_1 id (unique)
10
by: arnuld | last post by:
thanks
11
by: briankind | last post by:
Hello i have these radio buttons and i wish to have the corresponding textboxes to be visible when the radiobutton is selected. any Help? snippets. thanks thanks in adv Bry
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.