Andrew Ducker (andrewducker) wrote,
Andrew Ducker
andrewducker

Learning to loathe Javascript

I'm adding the templating function to my link poster, so that different people can have different looking posts.

And I figure that if I'm doing that then I should have a "reset to default" button, to set it back to an unfucked state.

Should be simple enough - all I need is a button that you click, and a function that sets some text in the textarea holding the template. How hard can it be?

The first thing that got me was that my button was called "ResetTemplate" and my function was called "ResetTemplate" and when I called "ResetTemplate()" from the onClick of the button, guess what happened?

Did you guess "Nothing at all"? Because that's exactly what happened. Which left me completely baffled for about 45 minutes until I created a "test" function, which worked, and then slowly tweaked it until it contained exactly the same text as the ResetTemplate function, at which point the only possible explanation was the name of the function. Which wasn't my idea of fun.

And then, having got that far, I reasoned that as I had a document, containing a form, containing a fieldset, containing a textarea, I should have something like:
document.DeliciousPoster.TemplateFields.PostTemplate.value = "Replacement Text";

But no, that doesn't work either. Because, it transpires, the PostTemplate textarea isn't part of the TemplateFields fieldset. It's directly part of the form. Which makes no sense to me at all, but there you go, apparently that's how it works.

So if anyone would like to point me in the direction of a good book, or tutorial, or somesuch, that would help me avoid constantly falling into these pitfalls, then I would appreciate it.

(I'm also constantly frustrated by the lack of autocomplete. Having to actually remember the names of functions/methods/properties feels hopelessly old-fashioned. But I don't think there's much I can do about that...)



Original post on Dreamwidth - there are comment count unavailable comments there.
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 25 comments