Javascript bookmarks, also known as bookmarklets, allow arbitrary Javascript to be run on the current web page. This is particularly useful for entering repetitive data into web forms.

A Javascript bookmark is simply an URL that uses the 'javascript:' protocol, followed by actual Javascript code. When a browser sees this type of URL, it runs the Javascript contained on the currently displayed web page. Modern browsers, such as Mozilla, will display the result of the Javascript expression in the webpage, but usually the intended use is to operate on the current page and redisplay it. In Mozilla, this can be accomplished by appending 'void(window)' onto the end of the expression. In Netscape 4.xx, the same can be accomplished with 'history.go(0)'.

To create a Javascript bookmark to fill in a form, first examine the source of the web page. Locate the form tag and note the value of the name attribute. Next, locate all the input tags for the fields you wish to fill in, and note their name attributes as well. Construct an URL like so:
javascript: document.form_name.input_name1.value = 'whatever'; document.form_name.input_name2.value = 'whatever'; ...; void(window)

Finally, create a new bookmark with the above string as the URL. The bookmark can be placed on your personal toolbar for even more convenience.

For example, to prefill a date input with todays current date, use
javascript: document.form1.date_input.value = (new Date()).toLocaleString(); void(window)

Replace void(window) with history.go(0) for Netscape 4.xx.

Log in or register to write something here or to contact authors.