Populate input fields on a web form

E

ero

Is it possible to input values into a web form from an external source
like a client-side javascript?

There is a web site that I'm viewing where I have to enter 5 values in
the form. 4 of the values don't change only one input field does. Is
it possible to create a javascript to run which would popluate the
non-changing values by executing the script or by pressing a button on
the script?

No experience at this so any examples would be helpful.

Thanks
 
R

Randy Webb

ero said the following on 8/11/2006 3:32 PM:
Is it possible to input values into a web form from an external source
like a client-side javascript?

There is a web site that I'm viewing where I have to enter 5 values in
the form. 4 of the values don't change only one input field does. Is
it possible to create a javascript to run which would popluate the
non-changing values by executing the script or by pressing a button on
the script?

No experience at this so any examples would be helpful.

You want a bookmarklet. Search Google and the Archives.
 
Y

Yanick

You could also use cookies that would populate the fields when the
body.onload of you document is triggered. (But this requires cookies to
be enabled.)

If you're using server scripting, use session vars to set the value
attribute of your input fields.
 
Y

Yanick

Randy Webb wrote:
[snip]
You want a bookmarklet. Search Google and the Archives.

..... I'm a little confused, honest, about suggesting bookmarklet from
you. On this link : http://en.wikipedia.org/wiki/Bookmarklet , it
explains that a bookmarklet is a "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... There's no bad intentions behind this simple
question, I'm just not sure how to relate...
 
R

Randy Webb

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="YourName";document.loginForm.userPassword.value="password";

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.
 
R

Richard Cornford

Yanick said:
Randy Webb wrote:
[snip]
You want a bookmarklet. Search Google and the Archives.

.... I'm a little confused, honest, about suggesting
bookmarklet from you. On this link :
http://en.wikipedia.org/wiki/Bookmarklet , it explains
that a bookmarklet is a "javascript:" pseudo-protocol,

They are, but they are javascript pseudo-protocol URLs stored as a
bookmark/favourite and activated by the individual user in order to act
upon a page they are viewing.
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... There's no bad
intentions behind this simple question, I'm just not sure how
to relate...

The specific recommendation is that javascript pseudo-protocol URLs
should not appear in the HREF attribute of a link (which is where the
onclick attribute is available as an equally reliable alternative and
does not induce the negative side-effects of activating a javascript
pseudo-protocol link (the browser getting the impression that is has
been navigated and so that the current page is about to be replaced).

Bookmarklets may have the same consequential side-effects, but they are
employed on an individual basis by the browser user, and in a way that
often makes the continued functionality of the web page being displayed
insignificant. That is certainly true in this case where the desire is
to enter values in form fields and then submit the form. The page
actually will be replaced shortly after the activation of the bookmark
so its continued functionality is not an issue.

Richard.
 
R

Richard Cornford

Yanick said:
You could also use cookies that would populate the fields
when the body.onload of you document is triggered. (But this
requires cookies to be enabled.)

If you're using server scripting, use session vars to set
the value attribute of your input fields.

Failing to quote (and top-posting) are often observed to coincide with a
failure to read the material in the preceding post. Where the OP says
"There is a web site that I'm viewing ..." (rather than "I have ...")
the implication is that the question represent a personal desire to
write known information into a fields of a form an a third party's web
site, so you suggestions are irrelevant to the situation.

Richard.
 
Y

Yanick

Richard Cornford wrote :
Failing to quote (and top-posting) are often observed to coincide with a
failure to read the material in the preceding post.

Well, thank you for pointing that out to me. I usually quote the
message, but I guess this time I really missed the right statement in
the question. It also explains the bookmarklet interrogation... My
mistake.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top