Why won't my jQuery onChange event trigger?

I am having trouble with simple jquery. Here is my html.

 <label>Select User</label>
    <span class="field">
        <select name="selectUser" id="selectUser">
            <option value="">Choose One</option>
            @foreach (var item in Model.Users)
            {
                <option value="@item.Id">@item.UserName</option>
            }
        </select>
    </span>

Here is the script:

<script>
$('#selectUser').change( function() {    
    alert("hello");      
});

now when i change the options in the select element nothing happens?

[EDIT]

SelecUser was a typo, I fixed it and still No alert message.

Answers


Because your id is selecUser instead of selectUser

Try this

$('#selecUser').change(function() {    
    alert("hello");      
});

you can try this as well

$('#selecUser').on("change",function() {    
    alert("hello");      
});

first of all You need to change the id for selector. also you either need to write that code in documnet ready or use jquery on.Use:

$(document).on('change','#selecUser',function() {    
 alert("hello");      
});

Your actual id is id="selecUser". Change it to selectUser


Need Your Help

what's the difference between folders 'installedApps' and 'applications' in websphere application server?

websphere

Normally, after we create profiles both DMGR and Node, we have folder applications under path $DMGRPROFILE_HOME/config/cells/$cellName and installedApps under path $NODEPROFILE_HOME/.

XCode: "To download this update...". Is this dialog normal?

xcode

I'm getting a dialog box asking to enter my apple developer id &amp; password in xcode. It just says something like "To download this update enter your information." then i goes away.