Chris
Chris

Reputation: 67

jQuery alert box not working

I have a tiny bit of code thats meant to show a javascript alert when a select list is changed value, but it doesnt seem to be working, could anyone give me a hand and let me know where im going wrong.

<script type="text/javascript">
$(document).ready(function(){
    $("#sources").change(function(e) {
        alert('This is what an alert message looks like.');
    });
});

HTML for the select is as follows:

<select name="sources" id="sources" multiple="multiple">
  <option value="">please select</option>
  <option value="5">Seek</option>
  <option value="6">friends</option>
</select>

Upvotes: 0

Views: 1368

Answers (1)

Jason
Jason

Reputation: 52523

Per your last comment, if jQuery is being used to generate the dropdown list on the fly, you need to use the .live() function to bind your dropdown:

$('#sources').live('change', function(e) { //do stuff });

Upvotes: 3

Related Questions