[thelist] Javascript bookmarklet to populate fields takes me to new page — why?

ben morrison morrison.ben at gmail.com
Wed Sep 23 04:19:24 CDT 2009


On Wed, Sep 23, 2009 at 9:58 AM, Barney Carroll <barney at clickwork.net> wrote:
> Hi folks,
>
> For a while now I've been working on an ecommerce web application whose
> content is largely arrived at by the filling in of large forms. As a way of
> saving valuable time I want to write javascript: bookmarklets which will
> populate the various forms with different content to make it easier to test
> a wide variety of permutations.
>
> So the bookmarklet so far is pretty much as follows:
>
> javascript:document.getElementById('productDescriptor1').value='this';document.getElementById('productDescriptor2').value='that';
>
> I don't want to submit, or take any real action apart from pure
> pre-population, so forcing values is really all I want to do.
>
> When I enter this into the address bar and hit enter, the resulting
> behaviour is problematic:
>
>   1. Only the last command takes effect. For the script above, only
>   productDescriptor2 gets 'that' assigned to it.
>   2. Immediately after the DOM script takes effect, I am given a document
>   whose only content is the last value I assigned. Just a blank page with
>   unformatted 'that', and the page I had been scripting for in my immediate
>   history.

You could look into creating a bookmarklet that inserts the JS into the page.

javascript:(function(){document.body.appendChild(document.createElement('script')).src='**
your external file URL here **';})();

That way you can keep maintenance of the files too :D

ben


-- 
Ben Morrison



More information about the thelist mailing list