467,888 Members | 1,361 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,888 developers. It's quick & easy.

Populate input fields on a web form

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

Aug 11 '06 #1
  • viewed: 6906
Share:
7 Replies
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 11 '06 #2
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.

Aug 12 '06 #3

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

Aug 12 '06 #4
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/
Aug 12 '06 #5
Yanick wrote:
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.

Aug 12 '06 #6
Yanick wrote:
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.

Aug 12 '06 #7

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.

Aug 13 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by C. David Rossen | last post: by
7 posts views Thread by jcnone | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.