samedi 3 janvier 2015

Passing form value to function variable


I have the following select option:



$region=$mydb->get_results("select region_name from region");
echo "Select Region:<SELECT NAME='region' ID='region'>";
echo "<OPTION VALUE='blank' SELECTED='selected'disabled='disabled'>-----------------------------</OPTION>";
foreach($region as $region){
echo "<OPTION VALUE='".$region->region_name."'>".$region->region_name."</OPTION>";
}
echo "</SELECT>";
echo '<input type="button" value="Find Facility" name="find_button" id="find_button" />';

<div id="key"></div>


What I want is to use the select option value to implement a button click function and post the results in a div on the same page.


I have defined a function.


this is the jquery i use to pass values to the the function:



jQuery(document).ready(function($) {
jQuery('#find_button').click(function() {

$('#key').html("");
var clickBtnValue = $(this).val();
var selectedregion = $('#region option:selected').val();
var ajaxurl="<?php echo admin_url( 'admin-ajax.php' ); ?>";
var data ={ action: 'facility_call', region:selectedregion};

$.post(ajaxurl, data, function (response){
alert('response gotten');
$('#key').html(response);
});
});


});


I want to pass values to the function vie the jquery but its not detecting.



function facility_call(){
$region=$_GET['region'];
}
add_action('wp_ajax_facility_call','facility_call' );
add_action('wp_ajax_nopriv_facility_call','facility_call' );




Aucun commentaire:

Enregistrer un commentaire