Is there any tutorial or code that help to poulate a textfield from a chosen value from a select box usuig AJAX or jQuery and PHP? Like in the picture ...
-
I think the answer you want is here: http://stackoverflow.com/questions/5592574/populate-select-from-other-select-value-using-jquery – OverZealous Aug 15 '11 at 07:54
-
3What I wouldn't give for a bit o' Comic Sans right now. – Ben Everard Aug 15 '11 at 07:55
-
@Ben [COMIC SAAAAANS!!!](http://www.explosm.net/comics/2301/) – Phil Aug 15 '11 at 07:56
-
Ha! I'll bookmark that one ;-) – Ben Everard Aug 15 '11 at 07:58
-
@OverZealous : I wouldn't use a Dynamic Dependent Select but from a selected item from a select box, I will go database and get some other data from and add it to the next textfield – Ali Ben Messaoud Aug 15 '11 at 08:03
2 Answers
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
//Please visit http://www.nokiflores.com
$(document).ready(function () {
$("#country").change(
function () {
$("#capital").val($(this).val());
}
);
});
</script>
<select id="country" name="country">
<option value="Delhi" >India</option>
<option value="manila" >phil</option>
<option value="tokyo" >japan</option>
</select>
<input type="text" readonly="readonly" value="" id="capital" name="capital" />
try this one: if you want to use php you will do it another way using ajax. Please visit http://www.nokiflores.com

- 257
- 1
- 9
I guess once you fill Delhi, the script can decide India, not opposite. However if you want to make a subset of cities available, for selected country: that makes sense.
To your question, for this you would need a mammoth list of all major countries and there cities.
My approach: In javascript make a array of 'country'. Make a csv list for each country (like in.csv, us.csv etc.)
Now using JS populate country option fields. Once country is selected, fire Jquery to fetch corresponding 'country-code.csv' using ajax. Then Simply make a selection list of fetched city-names.
Note: Some people would object on CSV, choose any file format you find appropriate.

- 6,518
- 10
- 53
- 80