Solved

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

Posted on 2013-01-28
4
312 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
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
why a radio button button and not a checkbox?
0
 

Author Comment

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

Author Comment

by:bbdesign
Comment Utility
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
Comment Utility
Hi
You can use checkbox for this functionality.

Here is example:

http://jsfiddle.net/Zdrnr/
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now