I need to call some data after clicking on an <option name="xxx">
in a <select>
in index.php.
The data that I need to call are stored in some dynamic arrays in a different page (select.php)
I have created some arrays in this way in select.php page
${$team} = array();
The string contained in $team that names the array is exactly the value and the name of each of my select options.
So for instance I have<option value="jack">jack</option>
in index.php and I have in select.php:
$team = "jack";
${$team} = ("name1", "name2", "name3");
(of course my explanation is simplified or I would create directly the $jack = array(); :-)!
I tried in this way but it doesn't seem to work:
index.php
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function fillSelect(){
var $select = $('#sub_category');
$select.find('option').remove();
if($('#root_category').val() != '#'){
$.getJSON( 'select.php', {
root_category: $('#root_category').val()
}
)
.done(function( data ) {
$.each( data, function( key, value ) {
$('<option>').val(key).text(value).appendTo($select);
});
});
}
}
</script>
<form name="module" id="idModule" method="post" action="action.php">
Chose team:
<select name="root_category" id="root_category" onChange="fillSelect();">
<option value="#">Selezionare</option>
<option value="jack">jack</option></select>
Here I want to show results<select name="sub_category" id="sub_category"></select>
</form>
and in select.php
json_encode(${$_GET['root_category']});