Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14611 reviews 1734 hosting providers

Questions & Answers

Ajax and PHP- How to change textbox value based on dropdown list with

May 8, 2012 by A007
hi, Does anyone know how to change the value of the textbox using Ajax and PHP, based on changing the value of the dropdown list. I have a list of currencies of countries. I want the value of the text book to change every time the value pf the dropdown list changes.
Can anyone please help me do this?
Thank you

1 Answer

0 votes
May 8, 2012 by expert
try this code

<select name="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)">
 <option value="">Select Country</option>
        <option value="1">USA</option>
        <option value="2">UK</option>
        <option value="3">China</option>
<input type="text" name="cur_code" id="cur_code" >
JavaScript Code
function getCurrencyCode(strURL)
  var req = getXMLHTTP();
  if (req)
               req.onreadystatechange = function()
          if (req.readyState == 4)
          {                if (req.status == 200)
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
        req.open("GET", strURL, true);
PHP code
        case "1" :
                echo "USD";
        case "2" :
                echo "GBP";
        case "3" :
                echo "YEN";