Reputation: 53
I have a drop down list:
@Html.DropDownList("CharacterID")
and the following jQuery:
$(document).ready(function(){
$("#CharacterID").on(change, "#CharacterID", (function () {
alert("I've Changed");
//var id = $('#CharacterID').val();
}));
});
which is not firing when I change one of the dropdown selections.
What can I do to fix this? I've looked at similar questions and answers and tried incorporating those but they haven't worked.
Here's what happens when I try running it in JSFiddle: http://jsfiddle.net/vgMdF/
Upvotes: 3
Views: 3024
Reputation: 71
I know this might be an old post but i thought it might help someone.
My issues was that some tags on my page created space e.g <script src = "https... the space betwee equals to (=) and also on script e.g <script was < script . So basically look at the space between the tags as it helped me. Also make sure all your tags have start and ending. Clean your page so that it is neat and easy to read. Thank you!
Upvotes: 0
Reputation: 5209
Try this :
$(document).ready(function () {
$('#CharacterID').change(function(){
alert("test");
});
});
Upvotes: 0
Reputation: 38102
You need to include jQuery in your demo and it should work as expected.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
For jsFiddle
, you can choose jQuery version from Extensions & Frameworks
tab.
Upvotes: 1
Reputation: 2333
The problem here is, your jsfiddle not ever include jquery, thats y it never run
check this fiddle http://jsfiddle.net/qg5Dh/1/
$(document).ready(function () {
$(document).on("change", "#CharacterID", (function () {
alert("I've Changed");
//var id = $('#CharacterID').val();
}));
});
it work well and the code work fine
Upvotes: 0
Reputation: 6148
Two problems:
change
is a string, not a magic variable. Add the quotations around it.$(document).on()
..
$(document).ready(function(){
$(document).on("change", "#CharacterID", (function () {
alert("I've Changed");
//var id = $('#CharacterID').val();
}));
});
You can see this working here: http://jsfiddle.net/h3q5d/
With your full page, and jquery loaded - it also works: http://jsfiddle.net/vgMdF/1/
Upvotes: 2
Reputation:
Could you try this:
$(document).ready(function(){
$("#CharacterID").on('change',function () {
alert("I've Changed");
//var id = $('#CharacterID').val();
});
});
Upvotes: 0