passing a input variable to php

23 views
Skip to first unread message

Jay Cohen

unread,
Sep 7, 2020, 4:16:23 PM9/7/20
to AJAX-chat
All 

I need help. I am trying to grab a variable from an input box and use is to do a search. 
I have 3 boxes State, City, Zip code and I want the user to select a state and then the state is used in the city search to only pull up cities from that state. 

I have an ajax script on my index page:

$(document).ready(function(){
$("#search-box-state").keyup(function(){
var state = $('#search-box-state').val();
$.ajax({
type: "POST",
url: "readState.php",
data:'keyword='+$(this).val(),
beforeSend: function(){
$("#search-box-state").css("background","#FFF");
},
success: function(data){
$("#suggesstion-box").show();
$("#suggesstion-box").html(data);
$("#search-box-state").css("background","#FFF");
}
});
});
});

function selectState(val) {
$("#search-box-state").val(val);
$("#suggesstion-box").hide();
}

the highlighted text is the variable and where the value is stored. On the next part of the script it enters readCity.php I am trying to get the variable to echo: 

$state = $_POST['state'];
error_reporting(E_ALL); ini_set('display_errors', 1);
#$sender = $_POST['state'];
#$receiver = $_POST['receiver'];
#$message = $_POST['message'];
echo"[ $state ]"; 

Every thing I try seems to not work. 

Any ideas?


Reply all
Reply to author
Forward
0 new messages