Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using a radio button as a toggle controlled by jQuery/Javascript

Posted on 2013-01-28
4
Medium Priority
?
322 Views
Last Modified: 2013-01-28
I have a simple radio button such as:

<input type="radio" id="noexercisebutton">

Open in new window


What I want to do is:

1. When you click the radio button, it selects.
2. When you click it a second time, it de-selects.
3. Additionally, I have Javascript that performs various tasks based on either (1) or (2), so I need to know which occurred.

I know how to make a radio button select or de-select via Javascript... the problem is that all of my event handlers seem to be conflicting with the inherent behavior of radio buttons. I tried "mouseup", but its unclear which happens first... a browsers handling of a radio button, or the timing of when Javascript sees a radio button as either checked or unchecked.

Is there some way to resolve this, or am I attempting something that is going to cause problems in various browsers?

Thank you!
0
Comment
Question by:bbdesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 38826733
why a radio button button and not a checkbox?
0
 

Author Comment

by:bbdesign
ID: 38826816
Hmm, good point. Maybe a checkbox would be a better idea.
0
 

Author Comment

by:bbdesign
ID: 38826827
That's what I'm going to do. Don't know why I didn't think of that, Monday morning and not enough coffee perhaps. Thanks!
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 38826834
Hi
You can use checkbox for this functionality.

Here is example:

http://jsfiddle.net/Zdrnr/
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question