aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes How would I check to see if a checkbox is checked or not with Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "How would I check to see if a checkbox is checked or not with Javascript?" Watch "How would I check to see if a checkbox is checked or not with Javascript?" New topic
Author

How would I check to see if a checkbox is checked or not with Javascript?

Toni Howlett
Greenhorn

Joined: Jan 18, 2012
Posts: 25
I just have a basic checkbox and I was going to add an onclick function to it... but I need it to do one thing if its checked and the other if not.

I bascially want to do if (checked) {} else {}

The check boxes do not currently have an id, but I can add one if necessary.


So again, how would I check to see if it is checked or not?
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

You don't need its id, the reference is available from the event instance.

If the element is checked, it will possess a checked attribute.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Toni Howlett
Greenhorn

Joined: Jan 18, 2012
Posts: 25
How do I do it tho?
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

What have you got so far? Where's your code? What specific problems are you having with it?

And personally, I'd never attempt event handling without jQuery assist. Life is too short to deal with IE's proprietary madness.
Toni Howlett
Greenhorn

Joined: Jan 18, 2012
Posts: 25
I can say already, it does NOT need to work for IE.

I don't really have code relating to this - which is why i'm asking.




the content of my javascript isn't important. It will run half of it if you click the box to be checked or it will run the other half of it if you click the box to be unchecked.


and I have 0 experence with jQuery
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003


Eric
 
IntelliJ Java IDE
 
subject: How would I check to see if a checkbox is checked or not with Javascript?
 
Threads others viewed
JSP : 508 Compliant
checkbox value to servlet
Checking whether check boxes are checked
Listening on Checkbox rendering in JLlist
Javascript - Arraylist
developer file tools