change() for select element is not working

I am learning Nodejs with node cookbook 2nd edition.

I like this book because it is teaching us with explaining sample code which looks very practical.

The example code is part of Browser-server transmission via AJAX part

Anyway the main question is that below is in the EX code, below is index.html file

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
        <script>
            $.get("http://localhost:8080/profiles",function (profile_names) {
                $.each(profile_names, function (i, pname) {
                    $("#profiles").append("<option>" + pname + "</option>");
                });
            }, "json");
            $("#formats, #profiles").change(function () {
                alert("2");
                var format = $("#formats").val();
                $.get("http://localhost:8080/profile/" + $("#profiles").val() + "." + format,
                    function (profile, stat, jqXHR) {
                        var cT = jqXHR.getResponseHeader("Content-Type");
                        $("#raw").val(profile);
                        $("#output").html('');
                        if (cT === "application/json") {
                            $.each($.parseJSON(profile), function (k, v) {
                                $("#output").append("<b>" + k + "</b> : " + v + "<br>");
                            });
                            return;
                        }
                        if (cT === "application/xml") {
                            profile = jqXHR.responseXML.firstChild.childNodes;
                            $.each(profile, function (k, v) {
                                if (v && v.nodeType === 1) {
                                    $("#output").append("<b>" + v.tagName + "</b> : " + v.textContent + "<br>");
                                }
                            });
                        }
                    }, 
                "text");
            });
        </script>
        <style>
            #frm, #raw {display:block; float:left; width:210px},
            #raw {height:150px; width:310px; margin-left:0.5em}
        </style>
        <title> INDEX </title>
    </head>

    <body>
        <form id="frm">
            Profile: <select id="profiles">
            <option> </option>
            </select>
            <br></br>

            Format:<select id="formats">
            <option value="json"> JSON </option>
            <option value="xml"> XML </option>
            </select>
            <br></br>
            <div id="output"></div>
        </form>
        <textarea id="raw"></textarea>
    </body>
</html>

Second, server.js file

var http = require('http');
var fs = require('fs');
var path = require('path');
var profiles = require('./profiles');
var xml2js = require('xml2js');

var index = fs.readFileSync('index.html');
var routes, mimes = {xml: "application/xml", json: "application/json"}

function output(content, format, rootNode) {
    if (!format || format === 'json') {
        return JSON.stringify(content);
    }
    if (format === 'xml') {
        return (new xml2js.Builder({rootName: rootNode})).buildObject(content);
    }
}

routes = {
    'profiles': function (format) {
        return output(Object.keys(profiles), format);
    },
    '/profile': function (format, basename) {
        return output(profiles[basename], format, basename);
    }
};

http.createServer(function (request, response) {
var dirname = path.dirname(request.url),
    extname = path.extname(request.url),
// $.get('http://localhost:8080/profile/' + $('#profiles').val() + '.' + format
    basename = path.basename(request.url, extname);

    extname = extname.replace('.', ''); //remove period


    response.setHeader("Content-Type", mimes[extname] ||'text/html');

    if (routes.hasOwnProperty(dirname)) {
        response.end(routes[dirname](extname, basename));
        return;
    }
    if (routes.hasOwnProperty(basename)) {
        response.end(routes[basename](extname));
        return;
    }
    response.end(index);    
}).listen(8080);

below is profiles.js file

module.exports = {
    ryan: {
        name: "Ryan Dahl",
        irc: "ryah",
        twitter: "ryah",
        github: "ry",
        location: "San Francisco, USA",
        description: "Creator of node.js"
    },
    isaac: {
        name: "Isaac Schlueter",
        irc: "isaacs",
        twitter: "izs",
        github: "isaacs",
        location: "San Francisco, USA",
        description: "Former project gatekeeper, CTO npm, Inc."
    }
};

I think at index file $("#formats, #profiles").change(function () { is not working.

I just input alert("2"); to test the code but I have never seen the alert.

I also tried to change code like

$("#formats").change(function () {,

$("#profiles").change(function () {

Both of them were not working neither.

Can you let me know what is the reason?

Either wrap your client-code in a DOM ready statement or move it to the end of the <body>. Your script is being executed before the page has rendered.