Solved

Need to target a checkbox

Posted on 2012-04-03
2
174 Views
Last Modified: 2012-04-09
I have a click event that sets a checkbox to be checked, however it is targeting all the checkbox on the page with the same class.

I only want to target the checkbox that was clicked. Using Mootools.

var checkEmail = $$('input.user-address');
          $$(".content .addcheck").addEvent('click', function () {
              alert('test');
              checkEmail.set('checked',true);            
          });
0
Comment
Question by:yando18
2 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 37803349
You need to use a unique id for any checkbox that you want to target individually.  Any reference using a class name always targets every member of the class.

Cd&
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37804240
What about : http://jsfiddle.net/hJbuD/
    $$(".content .addcheck").addEvent('click', function () {
        this.getPrevious('input.user-address').set('checked',true);             
    })¿

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

11 Experts available now in Live!

Get 1:1 Help Now