Hi
In my php page , there is a user registration form. Here the user has to select
the country, state, city from the drop down box. How this can be handled in php?
If a country is selected in a drop down box , its corresponding states should be
populated in the state drop down box. If a state is selected , its corresponding
cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What type of data storage and datastructure can be used. ? How this can be done in php + javascript ?
Thanks in advance
somaskarthic
10 22858
Hi
In my php page , there is a user registration form. Here the user has to select
the country, state, city from the drop down box. How this can be handled in php?
If a country is selected in a drop down box , its corresponding states should be
populated in the state drop down box. If a state is selected , its corresponding
cities should be populated in the city drop down box. Where all these data has to be stored and retrieved. What type of data storage and datastructure can be used. ? How this can be done in php + javascript ?
Thanks in advance
somaskarthic
Hi friend using AJAX functionality Its very easy to complete ur task.
I will send sample code to later using AJAX concept to drop down select option
Thanks . Please send the AJAX code .
Hi friend using AJAX functionality Its very easy to complete ur task.
I will send sample code to later using AJAX concept to drop down select option
Here is the ajax code this code i call one php file
This file u write your coading -
-
if(window.XMLHttpRequest)
-
{
-
http=new XMLHttpRequest();
-
}
-
else if(window.ActiveXObject)
-
{
-
http=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
-
var url = "countrylist.php?cid="+search_program.value;
-
//alert(url);
-
//mlsaddress=address;
-
http.open("GET", url , true);
-
-
http.onreadystatechange = countryprocess;
-
-
http.send(null);
-
//==jai
-
}
-
}
-
-
function countryprocess()
-
{
-
if (http.readyState == 4) {
-
// Split the comma delimited response into an array
-
if(http.status==200)
-
{ alert(http.responseText);
-
-
-
-
if(http.responseText!="No values")
-
{
-
var clist=http.responseText.split("_");
-
for(i=0;i<clist.length;i++)
-
{
-
var myclist=clist[i].split(",");
-
document.getElementById("search_country").options[i+1]=new Option(myclist[1],myclist[0]);
-
}
-
}
-
-
-
}
-
-
}
-
}
-
Hi
My web server is Fedora Core 4 Linux. If i use window.ActiveXObjects (for Ajax) , will it work ?
Please post your reply
-somaskarthic
Yes I hope its working My prodection serevr are linux machine Now working well
So you try to implement the code.
here u go, u have to change group into whatever u want. in groups there is specified array of groups. it is very simple
---> experim.php -
<html>
-
-
<head>
-
<title></title>
-
</head>
-
-
<body>
-
-
<SCRIPT language=JavaScript>
-
function reload(form)
-
{
-
// Setting the variable with the value of selected country's ID
-
var val=populate.countries.options[populate.countries.options.selectedIndex].value;
-
self.location='experim.php?countryId=' + val;
-
var val2=val+'&cityID='+populate.cities.options[populate.cities.options.selectedIndex].value;
-
self.location='experim.php?countryId=' + val2;
-
var val3=val2+'&groupID='+populate.groups.options[populate.groups.options.selectedIndex].value;
-
self.location='experim.php?countryId=' + val3;
-
}
-
JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green.");
-
</script>
-
-
-
<?php
-
function getCountryList()
-
{ $countries = array (
-
'1' => 'Bangladesh',
-
'2' => 'USA',
-
'3' => 'UK'
-
);
-
-
return $countries;
-
}
-
-
-
function getCityList($countryId)
-
{
-
// City list array
-
// First key of the array is the Country ID, which holds an array of City list
-
$cities = array (
-
'Bangladesh' => array ('Dhaka', 'Chittagong', 'What else'),
-
'UK' => array ('London', 'Cannot Remember'),
-
'USA' => array ('Washington', 'N.Y.', 'etc')
-
);
-
-
return $cities[$countryId];
-
}
-
-
-
function getGroupList($cityID)
-
{
-
$groups = array (
-
-
'etc' => array ('aka', 'Chg', ' else'),
-
'Washington' => array ('ndon', 'Cnnot member'),
-
'N.Y.' => array ('ashington', 'N.Y.', 'et')
-
//list of groups
-
-
);
-
-
-
return $groups[$cityID];
-
}
-
-
-
-
?>
-
<form action="experim.php" name="populate">
-
<?
-
-
// Retrieving the country list
-
$countries = getCountryList();
-
-
// Setting the variable if the country is selected for its city list
-
@$countryId = $_GET['countryId'];
-
@$cityID = $_GET['cityID'];
-
// Retrieving the city list if a country is selected
-
$cities = ($countryId) ? getCityList($countryId) : null;
-
$groups = ($cityID) ? getGroupList($cityID) : null;
-
-
if (!empty($countries))
-
{
-
// Generating the country drop down menu
-
echo "<select onChange='reload(this.form)' name='countries'>";
-
foreach ($countries as $value)
-
{
-
echo "<option value='$value'";
-
-
if ($countryId == $value)
-
echo "selected";
-
-
echo ">$value</option>";
-
}
-
echo "</select>";
-
}
-
-
if (!empty($cities))
-
{
-
// Generating the city drop down menu if a country is selected
-
echo "<select onChange='reload(this.form)' name='cities'>";
-
foreach ($cities as $value)
-
{
-
echo "<option value='$value'";
-
-
if ($cityID == $value)
-
echo "selected";
-
-
echo ">$value</option>";
-
}
-
echo "</select>";
-
}
-
-
-
if (!empty($groups))
-
{
-
// Generating the city drop down menu if a country is selected
-
echo "<select onChange='reload(this.form)' name='groups'>";
-
foreach ($groups as $value)
-
{
-
echo "<option value='$value'";
-
-
if ($groupID == $value)
-
echo "selected";
-
-
echo ">$value</option>";
-
}
-
echo "</select>";
-
}
-
-
-
-
-
if (!empty($groups))
-
{
-
// Generating the city drop down menu if a country is selected
-
echo "<select name='groups'>";
-
foreach ($groups as $key=>$value)
-
{
-
echo "<option value='$key'>$value</option>";
-
}
-
echo "</select>";
-
}
-
-
-
?>
-
-
</body>
-
-
</html>
Hi friend using AJAX functionality Its very easy to complete ur task.
I will send sample code to later using AJAX concept to drop down select option
elo there, is it okay if you send also to me the complete code... just for updating country, citym state.. please.. thank you so much..
I am also facing problem in making
the country, state, city drop down selct box.
but fails
if u have any plz send me
thax
Post your code attempt describing what problems you're having and I can split it off into its own thread.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: B. G. Mahesh |
last post by:
hi
In the registration form I have city, state, country fields. I was
wondering if there was a database available on the net which has the
list of states in each of the countries. That way when...
|
by: zoneal |
last post by:
I retrieved the following function from VB.NET help and added a few
statements for updating the datasource. But, it does not actually
commence the InsertCommand property of the DataAdapter in order...
|
by: steve_barker333 |
last post by:
Hi guys,
I'm designing a web-site that will allow users to look up other people,
based on certain criteria. The most important criterion is geographical
location. I've managed to find a...
|
by: jakas |
last post by:
Hi
In my php page , there is a user registration form. Here the user has to select
the country, state, city from the drop down box. How this can be handled in php?
If a country is selected in a...
|
by: icepoint |
last post by:
Hey everyone,
Can anyone tell me how to make dynamice drop down lists for country and states? I have the models for country and states build and have the country drop down list worked, so how can I...
|
by: help4me |
last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email....
|
by: pinocchio123 |
last post by:
hi friends...
in my php page 3 dropdownlist boxes are there.. ie country,state,city..
if country is selected, in onchange function.. corresponding states has to be populated in state...
|
by: tokcy |
last post by:
Hi everyone,
I need the world database of country state and city. Actually i have three drop down option in my project in 1st drop down country name should come from database and 2nd drop down...
|
by: bennever |
last post by:
Hi, I plan to use drop down lists to populate team results and will use the standard country/state drop down lists as the base code.
The question: how can I populate multiple (5) states from...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |