dflow Posted February 13, 2012 Share Posted February 13, 2012 i have the following code the get country_id ajax is executing the div as a test correctly how would i insert the result as a var in this line: setAutoComplete("searchField", "results", "../ajax_autocomplete/autocomplete_test.php?country_id=[iNSERT VAR]&part="); //need to insert the country_id <script type="text/javascript"> var selected_from_list = false; $(function(){ setAutoComplete("searchField", "results", "../ajax_autocomplete/autocomplete_test.php?country_id=&part="); }); //this working code: <script type="text/javascript"> function ajaxfunction(str) { if (str=="") { document.getElementById("country_id").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("country_id").innerHTML=xmlhttp.responseText; } } var testVars = ''; testVars = 'c='+country_id; xmlhttp.open("GET","getCountry_idfunc.php?country_id="+str,true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(testVars); return false; xmlhttp.send(); } </script> </script> yes I need to dive into ajax thanks Quote Link to comment https://forums.phpfreaks.com/topic/257067-insert-country_id-into-autocomplete-function/ Share on other sites More sharing options...
dflow Posted February 13, 2012 Author Share Posted February 13, 2012 ok some progress revised code the response is country_id undefined <script type="text/javascript"> function ajaxfunction(str) { if (str=="") { document.getElementById("country_id").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) { var id = document.getElementById("cid").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getCountry_idfunc.php?country_id="+str,true); xmlhttp.send(); } var selected_from_list = false; var u =document.getElementById("cid").innerHTML.id; $(function(){ setAutoComplete("searchField", "results", "../ajax_autocomplete/autocomplete_test.php?country_id="+u+"&part="); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/257067-insert-country_id-into-autocomplete-function/#findComment-1317875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.