Yanick said the following on 8/12/2006 12:21 PM:
Randy Webb wrote:
[snip]
>You want a bookmarklet. Search Google and the Archives.
..... I'm a little confused, honest, about suggesting bookmarklet from
you.
Fair enough. Read this entire post and at the bottom it explains why I
suggested a bookmarklet instead of anything else.
On this link : http://en.wikipedia.org/wiki/Bookmarklet , it
explains that a bookmarklet is a "javascript:" pseudo-protocol,
Yes, it uses the javascript
: pseudo-protocol.
and yet http://www.javascripttoolbox.com/bestpractices/#onclick
(a link from your post's signature) suggest that we should not use
this, rather use the onclick event...
The Best Practices document is totally, 100%, directed at code that is
in a webpage. A Bookmarklet is nothing more than a saved Favorites that
uses javascript to perform some action. Two different things entirely
and as such the Best Practices document isn't applicable as you can't
have a Favlet/Bookmarklet without the javascript
: pseudo-protocol.
There's no bad intentions behind this simple question,
A person who never asks questions never learns :)
I'm just not sure how to relate...
Think about your Bank's Website, or even Google Groups. Any site where
you have to log in. You have a log in form that you have to fill out and
then submit it. Let's say it looks like this:
<form name="loginForm" action="somewhere" method="post">
<input type="text" name="userName" value="">
<input type="password" name="userPassword" value="">
<input type="submit" value="Log In">
</form>
Every time you open that page, you type in your username and password,
click Log In. It's the same thing, over and over, every time you want to
log in.
Wouldn't it be easier, and neat, if you could just click a button/link
and it fill it in for you? That's part of what a Favlet/Bookmarklet will
let you do.
Save the above HTML in a local file, then open the page. In the address
bar of the browser, paste this snippet:
javascript
:document.loginForm.userName.value="Your Name";document.loginForm.userPassword.value="passw ord";
Then press Go and it will fill in the form for you, automatically. You
can save that snippet as a Favorites and then anytime you want to log
in, you simply open the page, then open the script/Favlet and it will
fill them in for you. You can add document.loginForm.submit() and it
will even submit the form for you, with a simple click.
Back to the OP's question, they wanted to fill out 4 inputs with the
same input every single time. A bookmarklet is the only way to do that
if you don't control the page it is on. If the page is your own, then
you simply edit the HTML and set the value of the inputs.
What they would have is a bookmarklet that looks something like this:
javascript
:
document.formName.input1Name.value="value here";
document.formName.input2Name.value="value here";
document.formName.input3Name.value="value here";
document.formName.input4Name.value="value here";
I added the line breaks so that it would be wrapped where I wanted it
wrapped, in a bookmarklet you can't have any line breaks, it is one long
continuous string.
Edit the form name and input names as they appear in the page in
question, then you can add one more line:
document.formName.input5Name.focus();
And it will put the focus in the one field you fill out manually.
Then, every time you open the page, you click your Favlet and you only
have one field to fill out. I have three of these on my Links bar in IE,
one logs into my email account, one logs in to my bank account, and the
third gives the browsers representation of the HTML of the page. All at
the click of a single button. Pretty neat and powerful things they are.
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/