This is a simple tutorial on how to get a dropdown list value using simple ajax and php
Create a html page named country.html and add the below codes,
HTML 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">India</option>
<option value="3">Uk</option>
</select>
<input type="text" name="cur_code" id="cur_code" />
Javascript CODE
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);
}
}
Now create a PHP file named code.php and add the below codes,
< ?php
$country=$_REQUEST['country'];
switch($country)
{
case "1" :
echo "USD";
break;
case "2" :
echo "Rupees";
break;
case "3" :
echo "Pound";
break;
}
?>
THATS IT!!!!!!!!!!!!!!!!
As you can see its pretty simple to understand this tutorial.
Incoming search terms:
- ajax drop down list of country by letter in php (59)
- ajax get textbox value (33)
- Changing textbox value from dropdown list using Ajax and PHP (29)
- Change dropdown list (options) values from database with ajax and php (11)
- how to interchange dropdwon on xml value using javascript (9)
- get textbox value in ajax (8)
- Two related drop down list by using Ajax & PHP (8)
- ajax get dropdown value (7)
- get textbox value in php (6)
- ajax show drop down text and value (4)
- ajax textbox value (4)
- copy value from dropdown show text box php (4)
- get textbox value ajax (4)
- Get textbox value in the Same JSP Page (4)
- how to get value using ajax (4)
- select option click in display value in textbox ajax and php database (4)
- textbox value from drop down list in html (4)
- access the value of next to current page using ajax php (3)
- add more textbox in javascript and how to retrieve the value using php (3)
- add value in dropdownlist through database in php (3)
- ajax code for add text box in jsp (3)
- ajax dropdownlist textbox php mysql (3)
- ajax mysql 3 drop down menu (3)
- ajax textbox select database values (3)
- ajax value in textbox (3)
- CobroPago vtiger CRM (3)
- coding of dropdown list in php using for loop (3)
- copy value from textbox to drop down menu using php and jquery (3)
- dropdown in textbox by using ajax php mysql (3)
- dropdown menu country code using php (3)
- for loop text box values in jquery (3)
- get textbox value in same page using php (3)
- get textbox value using php (3)
- get value through ajax (3)
- get value using ajax (3)
- getting the value in dropdown through textbox php (3)
- how to find textbox value in xml file using javascript (3)
- how to get dropdown value in textbox (3)
- how to get option list value in ajax php (3)
- how to get textbox value in php (3)
You will also be interested in ,
- Arrays In PHP
- Zip or Archive a directory using php
- Passing variables from javascript to php
- HTML E-mail Using PHP
- ScriptAlias and Alias in httpd.conf at a glance
- Remove Non-Alphanumeric Characters using php
- Get DNS Record using PHP
- Output buffering using ob_start in php
- Enabling curl on XAMPP for Windows
- Export MySQL to CSV (Excel) using php
