2

I want to retrieve the input value which is an array using AJAX.

<td>
 <label for=""><?php _e( 'State' ); ?></label>
 <input type="text" name="state_to[<?php echo $country_id ?>][]" class=" state_selection" placeholder="State name">
</td>

$('.location-wrapper').on('change', '.state_selection', function() {

        var country = $('#country_selection').val();
var self = $(this),
    data = {
        //state_id : self.find(':selected').val(),
        state_id : $('input[name="state_to[country][]"]').val(),
        country_id: $('#country_selection').val(),
        action    : 'select_zip_by_state_country'       
    };

    }); 

I am able to retrieve correct value fpr country but not for state. Please can someone help me with this?

1
  • can you provide a fiddle ? Commented Aug 28, 2017 at 12:28

1 Answer 1

1

Here you go with a solution

$('.location-wrapper').on('change', '.state_selection', function() {
  var country = $('#country_selection').val();
  var self = $(this),
  data = {
    //state_id : self.find(':selected').val(),
    state_id : $('input[name="state_to[' + country + '][]"]').val(),
    country_id: $('#country_selection').val(),
    action    : 'select_zip_by_state_country'       
  };
}); 

Hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.