Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Germany
[cities] => Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Berlin
)
[1] => stdClass Object
(
[id] => 2
[name] => Karlsruhe
)
[2] => stdClass Object
(
[id] => 3
[name] => Tuttlingen
)
[3] => stdClass Object
(
[id] => 4
[name] => Speyer
)
)
)
[1] => stdClass Object
(
[id] => 2
[name] => France
[cities] => Array
(
[0] => stdClass Object
(
[id] => 5
[name] => Paris
)
[1] => stdClass Object
(
[id] => 6
[name] => Lyon
)
[2] => stdClass Object
(
[id] => 7
[name] => Toulouse
)
[3] => stdClass Object
(
[id] => 8
[name] => Bordeaux
)
)
)
[2] => stdClass Object
(
[id] => 3
[name] => Lithuania
[cities] => Array
(
[0] => stdClass Object
(
[id] => 9
[name] => Vilnius
)
[1] => stdClass Object
(
[id] => 10
[name] => Kaunas
)
[2] => stdClass Object
(
[id] => 11
[name] => Klaipėda
)
[3] => stdClass Object
(
[id] => 12
[name] => Šiauliai
)
)
)
[3] => stdClass Object
(
[id] => 4
[name] => Italy
[cities] => Array
(
[0] => stdClass Object
(
[id] => 13
[name] => Rom
)
[1] => stdClass Object
(
[id] => 14
[name] => Milano
)
)
)
)
You can send a request to the PHP-Script "api.php" using POST-Parameters.
| Request-Parameters (POST) | Description | Response | |
|---|---|---|---|
| Name | Value | ||
| method | getCountries | Returns a JSON-Array with all countries. |
[
{
"id": 1,
"name": "Germany"
},
{
"id": 2,
"name": "France"
}
]
|
| method | getCities | Returns a JSON-Array with all cities of the requested country. |
[
{
"id": 9,
"name": "Vilnius"
},
{
"id": 10,
"name": "Kaunas"
}
]
|
| country | The ID of the requested country. | ||
Task 1
Please use the data given in the PHP-Variable
After that, please write a small JavaScript-Code using jQuery that implements the following conditions:
Please use the data given in the PHP-Variable
$aCountries to fill the two select-fields in the Form with the ID formStatic.After that, please write a small JavaScript-Code using jQuery that implements the following conditions:
- If no Country is selected, the Dropdown should show a placeholder "Please select a country"
- If no City is selected, the Dropdown should show a placeholder "Please select a city"
- The Button "send form" should be disabled if no country and/or city has been selected
- The second Dropdown should only show the placeholder and the cities of the selected country
- If no country has been selected, the second dropdown should only show the placeholder
Task 2
Please write a JavaScript using jQuery, that loads the countries and cities from the
The script should implement the following conditions:
Please write a JavaScript using jQuery, that loads the countries and cities from the
api.php and fills the two dropdowns in the form with the ID formAsync.The script should implement the following conditions:
- If no Country is selected, the Dropdown should show a placeholder "Please select a country"
- If no City is selected, the Dropdown should show a placeholder "Please select a city"
- The Button "send form" should be disabled if no country and/or city has been selected
- The second Dropdown should only show the placeholder and the cities of the selected country
- If no country has been selected, the second dropdown should only show the placeholder
- While the data is loaded from the server, no input should be possible
- Only the required cities should be loaded