Continent Table
- ASIA
- SOUTH AMERICA
Country Table
- Japan
- China
- Brazil
- Peru
This is the data in my table and i get all the data from continent table and country table like this
<select name="continent" class='required InputBox'>
<?php echo "<option value=''></option>";
foreach (Contintent() as $value) {
echo "<option id='" . $value[ 'sysid'] . "' value='" . $value[ 'name'] . "'>" . $value[ 'name'] . "</option>"; } ?>
</select>
This is for country
<select name="country" class='required InputBox'>
<?php echo "<option value=''></option>";
foreach (Country() as $value) {
echo "<option id='" . $value[ 'sysid'] . "' value='" . $value[ 'name'] . "'>" . $value[ 'name'] . "</option>"; } ?>
</select>
I want to know how to make it in a way that when i select the continent for example asia the option available for county will be the country in asia only which is japan and china. I also have another table after this which is city but if i get the logic here i can apply it to city. Any idea is appreciated
"UPDATE"
Found something here
One that i am not familiar with is the ajax can anybody try to explain how it work i want to know how i can pass the id of the select from this javascript snippet to my php function page here is the snippet..
$('.continent').change(function() {
var id = $(this).find(':selected')[0].id;
//alert(id);
$.ajax({
type:'POST',
url:'../include/functions.php',
data:{'id':id},
success:function(data){
// the next thing you want to do
console.log(data);
alert(id);
}
});
});
in my function the php
function Country(){
if(isset($_POST['id'])){
echo $_POST['id'];
}
}
The problem is the value of id is not passed how do i pass it onto the function.php i kind of out of idea here. Does it happened in success:function(data){
what do i do next?
FYI
The alert is ok it gets the id of the continent already it is just not passed to the function.php and console.log writes nothing and when i change the url to main page the page where the select are in the console.log returns the main page code.