MetaGuru
MetaGuru

Reputation: 43873

Why isn't this .change event firing in jQuery?

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>System Toolbox</title>
    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript" />
    <script type="text/javascript">

        $document.ready(function() {

            $("#SearchFor").change(function() {
                    alert($(this).val());
            });
        });

    </script>
</head>
<body>
    <div>
        Search for: <select name="SearchFor" id="SearchFor">
            <option value="company">Company</option>
            <option value="user">User</option>
            <option value="bundle">Bundle</option>
            <option value="course">Course</option>
        </select>
        <div id="SearchType"></div>
    </div>
</body>
</html>

No javascript errors per firebug...

Upvotes: 0

Views: 694

Answers (5)

Seb
Seb

Reputation: 25157

You wrote

$document.ready(function() {

But should be this instead:

$(document).ready(function() {

Upvotes: 1

Cody Caughlan
Cody Caughlan

Reputation: 32748

$document is not a valid reference to a jQuery object, try

$(document)

Notice the parenthesis

Upvotes: 0

KP.
KP.

Reputation: 13720

Your document.ready statement is incorrect. Should be:

$(document).ready(function() { 

    ...

});

Upvotes: 4

Pointy
Pointy

Reputation: 413996

should just be

$(function() {
  $("#SearchFor").change(function() {
                alert($(this).val());
        });
    });

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630607

Try this instead:

$(function() { //Shortcut for $(document).ready();
   $("#SearchFor").change(function() {
     alert($(this).val());
   });
});

Also, best to use script tags like this still:

<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>

See this question for more detail: Why don’t self-closing script tags work?

Upvotes: 0

Related Questions