Based on this link
http://www.w3schools.com/php/php_ajax_database.asp
This can fetch data on the database using combo box, by using change event.
Now what I'm trying to do is to load the data, after pressing the submit button.
This is my codes when I fetch the data using change event, This is working,
$("#cal_country").change(function(){
var str = document.getElementById("cal_country").value;
var str1 = document.getElementById("country_year").value;
var str2 = document.getElementById("country_month").value;
var foo = $("#cal_country").val();
if(foo)
{
$("#sortHolidayWrapper").css({"visibility":"visible"});
}
if (str=="")
{
document.getElementById("holiday_display").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("holiday_display").innerHTML=xmlhttp.responseText;
}
}
var url = holiday_preview_vars.plugin_url + "?id="+str+"&cy="+str1+"&cm="+str2;
xmlhttp.open("GET",url,true);
xmlhttp.send();
});
I tried to change the
$("#cal_country").change(function(){
to
$("#submit").submit(function(){
But its not working,. any idea for this one?
EDIT
$('#submitHoliday').submit(function(){
$.get('holiday_preview_vars.plugin_url',$('#submitHoliday').serialize(),function(response){
console.log(response);
var str = document.getElementById("cal_country").value;
var str1 = document.getElementById("country_year").value;
var str2 = document.getElementById("country_month").value;
if (str=="")
{
document.getElementById("holiday_display").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("holiday_display").innerHTML=xmlhttp.responseText;
}
}
var url = holiday_preview_vars.plugin_url + "?id="+str+"&cy="+str1+"&cm="+str2;
xmlhttp.open("GET",url,true);
xmlhttp.send();
$("#holiday_display").html(response);
});
return false;
});