0

I'm quite new to jQuery and I am trying to create a checkbox form, where you can add an element x to the list A (id=2), list B(id=3) and/or list C(id=77). The IDs are just an example for database purpose. So I created a form listing A, B and C. I gave each checkbox the value of the lists id.

Then I target the checkbox with

$("[id^=myCheckbox]").change(..)

when it is clicked and grab the id (of the list) via this.val().

My problem is that I only know the ID of the list which was clicked. How can I determine the value of the element x? I would like to have multiple elements, let's say x,y and z. I want to list for each element a checkbox form where you can select the list A, B and/or C.

    $("[id^=myCheckbox]").change(function() {

        var elementID = ????

        // selected list ID
        var listID = $(this).val();

        // determine checkbox state
        if(this.checked) {
            // add element to list (with ajax)
  
        }
        else {
            // remove element from list

        }
    });

I would be glad if somebody can help me. Thank you very much

PS:

Element X (databaseID = 11)
--------------
o List A (databaseID = 2)
o List B (databaseID = 3)
o List C (databaseID = 77)
--------------
Element Y (databaseID = 12)
--------------
o List A (databaseID = 2)
o List B (databaseID = 3)
o List C (databaseID = 77)
--------------
Element Z (databaseID = 13)
--------------
o List A (databaseID = 2)
o List B (databaseID = 3)
o List C (databaseID = 77)

So when the checkbox "List B" is clicked in the area of Element Y, I want to insert the ID of the Element Y and the ID of list B in the database: table: list_element

Now I only have the databaseID of the selected list, but I cannot determine the databaseID of the element..

bobmarley
  • 63
  • 1
  • 2
  • 6

0 Answers0