I need some help how to check if user has selected correct city in form. I use Java script and if user selects a country there is another list with cities being displayed (cities of this country). Sometimes it doesn't work correctly and I need the script to check if user selected the correct city.
What i need is:
1) if user selects country "USA", he can select only one of cities located in USA. If user selected no city, 'New York' will be entered in MySQL.
2) the same with germany.
3) not all countries have city lists. If user selected a country without city list, nothing must be entered in MySQL.
Below are my functions. It looks that they work fine, but the problem is that from time to time there is no city entered in MySQL even if user selected USA or Germany. I tested it many times - it works for me, but not for all users. I changed it many times - no success.
Thank you.
if ($country == 'USA' && $city != 'New York' and $city != 'Washington' and $city !='San Francisco') {
$city1 == 'New York'
}
else {
$city1 == '$city'
}
if ($country == 'Germany' && $city != 'Berlin' and $city != 'Frankfurt' and $city !='Cologne') {
$city1 == 'Berlin'
}
else {
$city1 == '$city'
}
if ($country != 'USA' and $country != 'Germany') {
$city1 = '';
}