Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:08:17+00:00 2026-06-03T06:08:17+00:00

So I have an array that gets created from a php loop that looks

  • 0

So I have an array that gets created from a php loop that looks like this:

echo '<input type="checkbox" name="types[]" id="types[]" value="' . $id . '"> ' . $type . '<br>';

And while it works just passing it to php, I wanted to do some updates and pass it to ajax
to pass to php so I can have the ajax do a fancy return on the page for me.

I’ve tried all types of ways to get it to pass to the ajax and over to php, but nothing works.

Here is the ajax code:

jQuery(document).ready(function(){

    $('#contactform').submit(function(){

        var action = $(this).attr('action');

        $("#message").slideUp(750,function() {
        $('#message').hide();

        $('#submit')
            .after('<img src="assets/ajax-loader.gif" class="loader" />')
            .attr('disabled','disabled');



        $.post(action, {
            types['types[]']: $('#types').val(),
            form_name: $('#form_name').val(),
            site_id: $('#site_id').val()
        },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown('slow');
                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled');
                if(data.match('success') != null) $('#contactform').slideUp('slow');

            }
        );

        });

        return false;

    });

});

Im trying to get this to work as well because the rest of the site uses the same functionality, and I would like to keep this the same way. I wouldn’t want to have to take
out the other ajax stuff on pages already created.

So any insight is greatly appreciated.

Thanks

Edit/Update:

So after setting the line like Meager explained:

echo '<input type="checkbox" name="types[]" class="types" value="' . $id . '"> ' . $type . '<br>';

And adjusting the ajax code to this:

    $.post(action, {
        form_name: $('#form_name').val(),
        site_id: $('#site_id').val(),
        types: $('.types').map(function(){ $(this).val(); });

    },

It just seems to be bypassing the ajax and posting right over to my process.php file with:

Array
(
    [types] => Array
        (
            [0] => 20
            [1] => 21
            [2] => 22
        )

    [site_id] => 112
    [form_name] => prd_svc
    [Submit] => Submit
)

==========================================

jQuery(document).ready(function(){

$('#contactform').submit(function(){

    var action = $(this).attr('action');

    $("#message").slideUp(750,function() {
    $('#message').hide();

    $('#submit')
        .after('<img src="assets/ajax-loader.gif" class="loader" />')
        .attr('disabled','disabled');



    $.post(action, {
        form_name: $('#form_name').val(),
        site_id: $('#site_id').val(),
        types: $('.types').map(function(){ $(this).val(); });

    },
        function(data){
            $('#message').html(data);
            $('#message').slideDown('slow');
            $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
            $('#submit').removeAttr('disabled');
            if(data.match('success') != null) $('#contactform').slideUp('slow');

        }
    );

    });

    return false;

});

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:08:18+00:00Added an answer on June 3, 2026 at 6:08 am

    Your attempt to create an “array” of elements via this: id="types[]" is wrong. You can’t group elements this way, and if you could, this still wouldn’t return an array of values: $('#types').val().

    You’ll have to assign each element a unique ID, or give them all a shared class and select by that:

    echo '<input type="checkbox" name="types[]" class="types" value="' . $id . '"> ' . $type . '<br>';
    

    Then, to turn an set of elements selected into their values, you can use map:

    // Collect all values
    $('.types').map(function () { $(this).val(); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that gets created from JSON. The array looks like this:
I have an associative array in awk that gets populated like this: chr_count[$3]++ When
I have the following php code that gets a serialized array from a mysql
I have a array that looks like this Array ( [provider] => Array (
I have the following php array that gets all values from a form full
I have created a page called profile.php that gets a value from mainpage.php, by
I have made an app that gets an array of addresses from a web
I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
I have an array that looks like: $fields = array( f1 => array(test), f2
I have an array that looks like $numbers = array('first', 'second', 'third'); I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.