From the archive

Javascript Woes - Mind the console

The other day I was working on some javascript...

I was working on a piece of code that would auto submit a form for me on change of a select box. I had a good little lesson happen. Since javascript possess a lovely ability to fail almost silently, knowing where to look for what could have gone wrong is key. Often times, in my noobishness, I completely space on the console. This was one of those times. I was sitting there staring at this...

  $(document).ready( function() {

    function updatePage() {
      $('form').submit();
    });

    $('#quarter').on('change', updatePage);
    $('#year').on('change', updatePage);
  });

And I was going CRAZY!!!!!!! I looked at the jquery docs about a million times. I was sure submit on the form was what I needed. I kept looking at my logic trying to figure out what I was doing wrong. When I viewed my page in the browser, I could select a new value and but nothing would happen. AAAAAHHHHHHHHH!!!! Oh, wait. The console!

Uncaught SyntaxError: Unexpected token )

What? Then as I look through my code, I see it - staring me in the face. );

All I had to do was remove a paren and a semi and boom!, working auto sumission.

  $(document).ready( function() {

    function updatePage() {
      $('form').submit();
    }

    $('#quarter').on('change', updatePage);
    $('#year').on('change', updatePage);
  });

:)

So just a friendly reminder... Mind The Console.