gebruiker ajax onchange select box geef de waarde van select door
HTML
<select name="sometest" onchange="javascript:call_ajax_fun(this.value);">
<option value="1"> A </option>
<option value="2"> B </option>
<option value="3"> C </option>
<option value="4"> D </option>
<option value="5"> E </option>
</select>
JS Ajax-functie
function call_ajax_fun(str)
{
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)
{
var result = xmlhttp.responseText;
if(xmlhttp.responseText!='')
{
document.getElementById('your_result_div_id').innerHTML =result ;
// put your result in your div
}
}
}
var url="get_result.php?pas_val="str;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
en je resultaatbestand zal als volgt zijn
get_result.php
<?php
if(isset($_REQUEST['pas_val']))
{
$pas_val = $_REQUEST['pas_val'];
if($pas_val<5)
{
$tbl = "table_1";
}
else
{
$tbl = "table_2";
}
// your table is in $tbl variable
// your your table here in your code
}
else
{
exit;
}
?>