Pat Gunn (dachte) wrote,
Pat Gunn

JS Ugliness

I'm weirded out that standards for Javascript programming are so low. Having made a more-or-less a successful first project, where I really rushed to get it done, cut corners, and just did the first thing that came to mind (that worked) to solve problems, I'm going back and refactoring it now, in some cases trying to learn best practice with some good documentation.

I'm sad that it's not actually possible to make things clean, and one of the kludges I am least proud of seems to be standard practice.

Ordinarily with a form in a page, you have a bunch of form elements, and you have some way to submit the form, which causes your browser to scoop up the state of all those form elements, bring you to a few webpage, and give the webpage the state of that form in some fashion (I could explain, but let's gloss over those details).

One of the points in my demo is that I want to be able to do forms that talk to javascript that manipulate the currently loaded page and then reset themselves, rather than loading an entirely new page. This is fun because it doesn't take anything on the webserver end, and in fact doesn't even require a webserver; I'm doing development with a flat HTML file with all the javascript packed into it, using a file:/// url.

Still, forms are useful; the widgets they provide are really useful. So, how do I use those widgets but prevent the form from ever doing a submit?

My hackish solution was to cheat; if you view the source of my demo, you'll find that I hook "onSubmit" events, use it as the main entry point into my code, and then return false, using a mechanism normally used by form validation to back out of the submission. I also have code to clean up the entry box. Ugly, but ok for a proof of concept. Or so I thought. I was shocked to find that my ugly hack seems to be standard practice. WTF. It's not even that robust; if your javascript doesn't pass muster with the parser, a submission will happen anyhow, when it probably should never happen. Highly uncool. I'm looking for better solutions, but really bothered that the status quo sucks so much.

Tags: tech

  • Sneezes while Sneaking

    I recently came across Kat Walsh (a prominent-and-awesome Wikipedian I used to know)'s Women on Wikipedia essaylet. I don't have a lot to add on…

  • The Prajna of British Anicca

    I went for the Encyclopedia Britannica's offer of free access to their online edition to web publishers (which includes frequent bloggers). As I…

  • Napes and Latters

    A few amusing things on youtube: Mary Poppins ... sort of.. The Ring ... sort of.. The Shining ... sort of.. Home Alone ... spot on..…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded