Get textbox value from dropdown using ajax and php
Get textbox value from dropdown using ajax and php
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.
Get textbox value from dropdown using ajax and php,Incoming search terms:
- ajax drop down list of country by letter in php (59)
- ajax get textbox value (36)
- Changing textbox value from dropdown list using Ajax and PHP (31)
- @getco com sa (16)
- get textbox value in ajax (12)
- Change dropdown list (options) values from database with ajax and php (11)
- ajax get dropdown value (10)
- php dropdown get selected value XML (3)
- php mysql fetch data into textbox with select from drop down list & program example with (2)
- php get dropdown text (2)
- ajax how to fill textbox value from mysql according to dropdown values (2)
- php populate dropdown from another dropdown ajax (2)
- how to fetch data in textbox using combobox in php (2)
- how do i change textbox value automatically based on more than one dropdown from database using ajax (2)
- change the text value according to select from database using ajax (1)
- change php variable when dropdown value changes ajax (1)
- change textbox value after selecting three dropdown values from database in php (1)
- yii2 populate textbox with input textbox value (1)
- code for display text in textbox from database when dropdown list checked (1)
- combobox onchange text php mysql (1)
- combobox to textfield php ajax database onchange jquery (1)
- copy selected value in dropdown list in another textbox using jquery ajax (1)
- demo for searching value in textbox using php (1)
- dependent drop down list with php and ajax when page load (1)
- cast textbox ajax (1)
- can we make drop down list to get values from 00 to 59 dynamically using php (1)
- bind dropdownlist text using id to get particular value in php (1)
- ajax auto retrieve data from database when textbox has already value (1)
- ajax function to pass one field value to another file (1)
- ajax code for onkepress event on textbox for making dropdown (1)
- ajax instant textbox value encoding (1)
- ajax load textbox (1)
- ajax on dropdowm in php (1)
- ajax populate data from database in a textbox php (1)
- Ajax sends ON value for textbox (1)
- ajax single dropdown with database using php (1)
- ajax single select box multiple option using mysql table in php (1)
- ajax with list menu and textbox (1)
- Auto Calculate Textbox Value Using Combobox Onchange Event and php database (1)
- auto fill another textbox by entering value in textbox php mysql example (1)
instead of var req = getXMLHTTP();
write var req = new XMLHttpRequest();
Great!! This is good example for dynamic drop down menu using jQuery. It just made my work easier. It saved lot if time. This was so easy to follow and exactly what I was looking for.
Thanks.