« | Debugging JavaScript |
» |
This post is in the nature of being a shout out to see if anyone can give me some help. I'm completely self taught on JavaScript and it probably doesn't help that, given my programming background1, I still struggle with getting my head around anything object oriented. My background is functional languages.
Anyway I get by, largely by heavy use of Google and squinting at other people's code. But it's frustrating, especially when I'm debugging as often I get code which simply doesn't work with nothing on the browser's error console to give me any clue as to what's going on.
Take this afternoon as an example. I've got a web form which I want to validate client side before allowing the user to submit it. All pretty straightforward stuff and I've done it many times before. It's even easier these days as I'm a convert to jQuery so I no longer have document.getElementById()
scattered through my code.
Anyway the problem I had was that for the validation I was using an <input type="button"
with an onclick
attribute to fire off a function to do the final validation and then submit the form via a call to $('#adform').submit();
if all was well.
This function worked fine if the fields still needed work but if the form validated it wouldn't submit. Very odd. No error on the console. Nothing happening at all. I went around in circles for ages trying different things.
In the end, after dumping all the properties of the form
object, I tracked it down. I'd stupidly given the button an id
, even though it turned out not to need one at all, and the id
I'd given it was 'submit'.
So, if I understand the problem correctly, form.submit
was now an HTML button element not a submit function.
D'oh!
But here's the question: that's the sort of thing that I can imagine the right sort of tool picking up for me. Does anyone have ideas?
I was vaguely impressed with TypeScript when it was first announced2 although I'm not sure if it would have helped me in this particular situation and I'm not sure if there's support in Xemacs which is my preferred programming editor.
Tags: JavaScript | Written 23/05/13 |
« | » |