I am using MVC pattern for building a PHP movie web. in View class, I print out the select box that contain an array.
print "
<div>
<div class='top-nav'>
<label for='actor'>Actor:</label>
<select name='actor' id='id-actor' onchange='movieFilterChanged();'>
<option value='all'> Select All </option>
";
foreach($actors as $actor){
print "
<option value='".$actor['actor_id']."'> ".$actor['actor_name']." </option>
";
}
print "
</select>
</div>
";
The JS function movieFilterChanged()
will be triggered when value was selected. I wrote the simple JS function :
function movieFilterChanged(){
var actor = document.getElementById('id_actor').value;
if (actor != 'all')
alert("actor");
}
But this JS function is not triggered.