Page 1 of 1

pass ajax variable data to php variable in same form

Posted: Tue Mar 08, 2011 12:14 am
by thenndral
Hello all,

I need to get data from ajax and sent to php in a same form.

Let me explain. when the user click "makeChart" button date_start and date_end data pass through ajax and return value is 2 data ie main_view_tot and main_view_avg.
this woks fine.

After getting these two data I want to export those data to excel sheet. so that i need to sent the data to php [hyperlink]. i want to pass the querystring data through the link.
I don't know how to pass the data to php after getting from javascript/ajax.

Any ideas are welcome.

Below is my code, let me know how to solve this.Please help me.

Code: Select all

<?
/*
$post_main_view_tot = 1000;
$post_main_view_avg = 2000;
*/

$html_listData = "&nbsp;<a href='#'><input  type='button' value='Report XL123' onclick='location.href=\"export_xl.php?M_tot=$post_main_view_tot&M_avg=$post_main_view_avg\"'/></a>";
?>
<script language="javascript" type="text/javascript"> 

var html1_VT;			
var html2_VT;	

function makeChart() {
	var chart_mode;
	date_start = document.getElementById('formReport')['dateStart'].value;
	date_end   = document.getElementById('formReport')['dateEnd'].value;
	var param = '&date_start='+date_start+'&date_end='+date_end;
	sendRequest("report_ad.php", param, response_viewChart_ByAD, "POST");
}

function response_viewChart_ByAD() {
	var return_value1, return_value2;
	
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			return_value1 = "";
			return_value2 = httpRequest.responseText;
			//alert(return_value2);

			if ( return_value2 ) {
				arr_chartSet = return_value2.split(delimeter1);
				site_count = arr_chartSet[0];
				
				main_view_tot = arr_chartSet[1]; // how can i pass this value to $post_main_view_tot.
				main_view_avg = arr_chartSet[2]; // how can i pass this value to $post_main_view_avg.
				
				document.getElementById('M_tot').value = main_view_tot;
				document.getElementById('M_avg').value = main_view_avg;
				
				document.getElementById('main_tot').innerHTML = main_view_tot;
				document.getElementById('main_avg').innerHTML  = main_view_avg;				
				
				return true;
			} else {
				alert(MSG_noHaveChartData);
			}
			
		}
	} else {
		//alert("error " + httpRequest.readyState);
	}
}

</script>
</head>

<form id="formReport" method="post" >
<input type="hidden" id="M_tot" name="M_tot" />
<input type="hidden" id="M_avg" name="M_avg" />
<input type="hidden" id="S_tot" name="S_tot" />
<input type="hidden" id="S_avg" name="S_avg" />

<input type="hidden" id="contract_Start" name="contract_Start" />
<input type="hidden" id="contract_End" name="contract_End" />

<input type="hidden" id="post_export_filename" name="post_export_filename" />
<input name="btn4" type="button" class="btnb b4" value="chart" onclick="makeChart()">
<?php		echo $html_listData;	?>
</form>
</html>
thanks in advance,
thenndral.