Jump to content

insert Country_id into autocomplete function


dflow

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.