0

I'm trying to make a dependent drop down with AJAX. I managed to get the chosen variable but I can't pass it to the PHP. Here's my code:

action.js

window.onload = function($) {
jQuery("#brand").change(function() {
//get the selected value
var selectedValue = this.value;

//make the ajax call
jQuery.ajax({
    type: 'POST',
    data: {option : selectedValue},
    success: function() {
        console.log(selectedValue);
    }
});
});
}

the php

$cars_post_id = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_value='".$_POST['option']"'" );
$separated = implode(",",$cars_post_id);
$car_model = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='Model' AND post_id IN ($separated) GROUP BY meta_value ASC");

1 Answer 1

1
var selectedValue=$(this).children(":selected").val();

Use this for getting value for select tag

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.