Jump to content

jQuery check two boxes are checked


nano

Recommended Posts

Hey Guys,

 

I am a little stuck at the moment. I have the following HTML:

 

<tr>
    <td class="place">Cardiff</td>
    <td class="selection"><input type="checkbox" name="Cardiff" class="been" value="CA_1" /></td>
    <td class="selection"><input type="checkbox" name="Cardiff" class="going" value="CA_2" /></td>
</tr>
<tr>
    <td class="place">Amsterdam</td>
    <td class="selection"><input type="checkbox" name="Amsterdam" class="been" value="AM_1" /></td>
    <td class="selection"><input type="checkbox" name="Amsterdam" class="going" value="AM_2" /></td>
</tr>

 

I am playing with Google Maps API and need to show different marker dependent on what the user checks.

 

If they select the input with class been - show marker1.png

 

If they select the input with class going - show marker2.png

 

Then the fun one which I need help with..

 

If they select both checkboxes in the same table row, then show marker3.png

 

This is what I currently have:

 

$('tr input[type="checkbox"]').click(function() {
    
        var noCheckboxes = $('input[type=checkbox]');
        var selected = this.value;
        var boxClass = $(this).attr("class");
        var location = selected.substring(0, selected.indexOf('_')); // example: CA
        var boxType = boxClass.substring(0, boxClass.indexOf(' ')); // been or going due to focus

        // Find out if multiple checkboxes are checked for single marker
        if(noCheckboxes.filter(':checked').length > 1 && noCheckboxes.filter(':checked').attr('value', selected).length > 1) {
            plotImage = 'marker3.png';
        } else {
            // Set plotImage dependant on checkbox checked
            switch (boxType) {
                case 'been':
                    plotImage = 'marker1.png';
                    break;
                case 'going':
                    plotImage = 'marker2.png';
                    break;
                default:
                    plotImage = 'marker1.png';
            }
        }
        
});

 

Sooo basically, how can I give the markers a different image if both the check boxes are checked and in the same row only.

 

My above jQuery fails badly :(

 

Any help would be appreciated. Cheers.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.