Reputation: 3181
I'm developing a web application in PHP and Javascript and I'm trying to run some code on the change of the value of select here's my code, but it isn't working :
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" >
$("#projectType").on("change",function() {
alert( "hello");
});
</script>
and here's the select code:
<select name="projectType" id="projectType" >
<?PHP foreach($projectType as $projectTypeID => $projectTypeName)
{echo '<option value="'.$projectTypeID.'|'.$projectTypeName.'">'.$projectTypeName.'</option>';}?>
</select>
and ideas?
Upvotes: 0
Views: 79
Reputation: 384
Make sure your change event isn't assigned until the DOM is ready. You probably want this:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" >
$(function(){
$("#projectType").on("change",function(){
alert("hello");
});
});
</script>
Upvotes: 1