Pat Gunn (dachte) wrote,
Pat Gunn
dachte

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
Subscribe

  • Controversial Opinions in Programming

    I like that recently there's been a meme floating around, started by one good blog post that got a lot of airtime, of posting and then talking about…

  • Firefox and Clipboard-clobbering

    I often find that my PRIMARY clipboard (the one associated with mouse selections in the X Window System, not to be confused with the CLIPBOARD…

  • Powershell and talking to running apps

    I am committed to Unix, but sometimes I worry that the development culture we have is leading us to fall behind on some important fronts. We have a…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 6 comments