Table based on dropdown selection ajax help!?
Table based on dropdown selection ajax help!?
drc83
Posts: 11Questions: 0Answers: 0
I have a page which has a dropdown box.
On selection a value is sent to a php script (Ajax), based on the value a html table is created
and sent back to the responseText.
The table is outputted to the html page, I want the table to have sortable columns, so I have used jquery datatables for this, but it is not working.
I have cut and pasted the exact table into the html and ran the page, and then sorting works.
Please can anyone help / advise to fix this?
Note the table output from the php is outputted inbetween ........ ...etc
Here is the rest of the code on the HTML page:
[code]
$(document).ready(function() {
$('table#example').dataTable( {
"sPaginationType": "full_numbers"
} );
} );
function selMetal(str,str2){
if (str==""){
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","sql.php?m="+str+"&s="+str2,true);
xmlhttp.send();
}
[/code]
On selection a value is sent to a php script (Ajax), based on the value a html table is created
and sent back to the responseText.
The table is outputted to the html page, I want the table to have sortable columns, so I have used jquery datatables for this, but it is not working.
I have cut and pasted the exact table into the html and ran the page, and then sorting works.
Please can anyone help / advise to fix this?
Note the table output from the php is outputted inbetween ........ ...etc
Here is the rest of the code on the HTML page:
[code]
$(document).ready(function() {
$('table#example').dataTable( {
"sPaginationType": "full_numbers"
} );
} );
function selMetal(str,str2){
if (str==""){
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","sql.php?m="+str+"&s="+str2,true);
xmlhttp.send();
}
[/code]
This discussion has been closed.
Replies
[code]
...
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
$("#example").dataTable()
}
...
[/code]
alternatively, and possibly better if you're going to be switching that select input more than once, you could return just the data for the table from the PHP as JSON and use the fnClearTable and fnAddData api methods