2

Code: jsfiddle.net/bVgwc/2/

I can NOT produce a jquery code to make Darc checked (below) when I manually check Darc (above) And the same with the rest two.
check Darc above --> Darc needs to be automatically checked below
check LaVoiture above --> Lavoiture needs to be automatically checked below
check Gerli above --> Gerli needs to be automatically checked below.

Makes sense?

Ive made another jquery code for another exact same situation BUT I cant adapt it for this case.

Can somebody please write the code in that link i posted above where its the live code?

Guys, this code works BUT its for that particular situation: jsfiddle.net/F7nBL/6/

Can soembody ADAPT it to this current situation taht im presenting here? maybe this way is easier

1
  • 4
    Say that 10 times, fast. Commented Dec 15, 2010 at 22:40

2 Answers 2

1

Fixed in fork *note actually fixed now. did a fork instead of an update...

logic behid it is, give all checkboxes the same class, 'checkDbl' and give each matching pair of checkboxes the same class, Darc, VL, Geril and a rel that matches that second class. then tie a onChange to the class checkDbl that changes all elements fo the class that is the same as THIS rel to be the same checked state...

 $('.checkDbl').change(function(){
       $('.'+$(this).attr('rel')).attr('checked',$(this).attr('checked'));
    }); 
Sign up to request clarification or add additional context in comments.

5 Comments

The checkDbl class wasn't assigned to the checkboxes when I looked.
I understand what your u are saying but its not working when u check it
you are my hero, btw how can i contact you? maybe i can hire you in the near future for other projects
find me by way of fatherstorm.com
@Father You are creating the $(this) object two times. You can optimize your code by caching the object: var $this = $(this);
1

If you are looking for code that works on your existing HTML, the following should work

$("input[type=checkbox]").click(function(){
    var id = $(this).attr("id");
    var fieldName = id.substring(id.lastIndexOf("_")+1);
    var checked = $(this).attr("checked");
    $("div label").each(function(){
        var text= $(this).text().trim();
        if (fieldName == text){
            $(this).find("input").attr("checked",checked);
        }

    });
});

It is probably not the most efficient code, but it does the job. Not that you'll need to change the id of the Darc checkbox to CustomFields[25_3]_Darc instead of CustomFields[25_3]_Dark for it to work on the Darc checkbox.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.