0

I am dealing with some jQuery code that is a bit confusing to me. I'm still new to jQuery, and I haven't tried to build a query string using it before (I'm more familiar with C#/.NET).

What I want to do is attach the value of a checkbox to a query string so it can be used on another page for an email submission. If the checkbox is checked, then the value of it should be submitted. If the checkbox is unchecked, then nothing should be submitted.

Note: The majority of the code is not mine but someone else's that I have to work on.

Here is the jQuery code (the query string parameter I want to set is member: [what to put here]):

        if(success == 0)
        {
            if($('.catchTB').val().length == 0)
            {
                //CHECKBOX GROUPS
                var personalInsurance = '', specialtyInsurance = '', commercialInsurance = '';
                $('.personalInsurance:checked').each(function() {
                    if(personalInsurance.length > 0)
                        personalInsurance = personalInsurance + ", ";
                    personalInsurance = personalInsurance + $(this).val();
                });   
                $('.specialtyInsurance:checked').each(function() {
                    if(specialtyInsurance.length > 0)
                        specialtyInsurance = specialtyInsurance + ", ";
                    specialtyInsurance = specialtyInsurance + $(this).val();
                });  
                $('.commercialInsurance:checked').each(function() {
                    if(commercialInsurance.length > 0)
                        commercialInsurance = commercialInsurance + ", ";
                    commercialInsurance = commercialInsurance + $(this).val();
                });

              //this is the code that sets up the parameters of the query string, and member is the one I want to set with the checkbox value
                $.get("/UserControls/Forms/GetAQuoteProcessor.aspx", { fname: $('.firstName').val(), lname: $('.lastName').val(), email: $('.email').val(), telephone: $('.telephone').val(), address: $('.address1').val(), address2: $('.address2').val(), city: $('.city').val(), ddl: $('.ddl').val(), zipcode: $('.zipcode').val(), personalInsurance: personalInsurance, specialtyInsurance: specialtyInsurance, commercialInsurance: commercialInsurance, member: [what to put here], comment: $('.comment').val(), catchTB: $('.catchTB').val() },
                  function(data){
                $('#getAQuote').css('display', 'none');
                $('.response').html(data);
                  });
            }
        }
    });

This is the checkbox:

        <td  colspan="3" valign="top"><input type="checkbox" class="personalInsurance checkBox" id="member" value="Member of the NDGAA, PCSA, or Pet Professional Guild" /> Check if a you are a member of the NDGAA, PCSA, or Pet Professional Guild</td>
Dejsa Cocan
  • 1,539
  • 3
  • 19
  • 56

1 Answers1

0

To find out if a checkbox is checked, use .is(':checked') like this:

var checked = jQuery('#member').is(':checked');

It will return a boolean.

Lian
  • 2,197
  • 2
  • 15
  • 16