Update app.js

Modified select to happen only when connect succeeds.