« back

Javascript Woes - Mind the console

16 May 2013

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...

1   $(document).ready( function() {
2 
3     function updatePage() {
4       $('form').submit();
5     });
6 
7     $('#quarter').on('change', updatePage);
8     $('#year').on('change', updatePage);
9   });

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.

1   $(document).ready( function() {
2 
3     function updatePage() {
4       $('form').submit();
5     }
6 
7     $('#quarter').on('change', updatePage);
8     $('#year').on('change', updatePage);
9   });

:)

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

comments powered by Disqus