The trials and tribulations of JavaScript: part 7,984,132

I spent far too much time over the last few days wrestling with a particularly intractible JavaScript problem. I had a funky little form which the guys had built me, with an image in place of a submit button, which called the JavaScript form.submit() function to, err, submit the form. Problem is, it didn’t. It kept telling me “object does not support this property or method”. Which is damn stupid, because every fule kno that JavaScript supports the form.submit() method. My JavaScript book tells me so. The numerous website I’ve built which use it tell me so. The websites I scoured for insights into my problem told me so. I was particularly disheartened when I tried pasting one piece of sample code alongside my own, and found that their form.submit() worked and mine didn’t.

In the end I gave up, and asked guyd2 if he could help. I felt kinda bad doing it, but I know that Guy has an even higher pain threshold than I do for dealing with such problems, plus he’s encountered a few in his time. Luckily, he had encountered this one before, and after what seemed like a very short time (may have been a couplea hours, but short compared to the amount of headbanging time I had already devoted to this problem) he came up with a solution. Don’t call your submit-button-replacement-image “submit”. The IMG tag had both its NAME and ID properties set to “submit”, and this was confusing the damn fool JavaScript into thinking that when I said form.submit() I was asking it to do something kinky with the image. I changed the image name and id to “subButton” and, lo and behold, everything worked. Simple problem, simple solution. So why, as ever, did it take 2 days to get to the bottom of it?

Thanks Guy.

Leave a Reply

Your email address will not be published. Required fields are marked *