I am using the following script
<script>
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getCurrencyCode(strURL)
{
var req = getXMLHTTP();
if (req)
{
//function to be called when state is changed
req.onreadystatechange = function()
{
//when state is completed i.e 4
if (req.readyState == 4)
{
// only if http status is "OK"
if (req.status == 200)
{
document.getElementById('cur_code').value=req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
to get the currency of some countries using AJAX, based on dropdown value.
<select id="termid" class="selectfield" onChange="getCurrencyCode('find_ccode.php?country='+this.value)">
find_ccode.php is
$country=$_REQUEST['country'];
switch($country)
{
case "1" :
echo "USD";
break;
case "2" :
echo "GBP";
break;
case "3" :
echo "NPR";
break;
}
and my textbox is
<input type="text" name="cur_code" id="cur_code">
What I want is to assign the country’s currency code into a PHP variable and echo it on every change. How to do this?
Thank you
if you are usign jQuery why bother with custom HTTPRequest ?
Later edit:
then
find_ccode.phpcould be: