/    Sign up×
Community /Pin to ProfileBookmark

Using javascript to get form input name and value pairs

I’m trying to figure out how I can create javascript code in a bookmark that pulls the names and values from the form inputs in a loaded document.

In addition it would also be nice if the code knew which form has focus and just pulled the input names and values from that form.

I’ve been trying to figure it out, but the only portion I could get to work so far is:

[CODE]javascript:(document.write(document.forms[0].elements[0].name))[/CODE]

I don’t really know where to go from here. Writing javascript in a javascript?) seems to be different and beyond my level.

Any help would be appreciated. Thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@joecap5authorSep 12.2010 — Sorry. I'll need some more help than that.
Copy linkTweet thisAlerts:
@Declan1991Sep 12.2010 — Using JavaScript like that is absolutely identical to writing it any other way, except in one little way. Statements that return a value other than null must be wrapped in void.javascript:void(mynum = 10);alert(mynum);
Copy linkTweet thisAlerts:
@joecap5authorSep 13.2010 — OK. Thanks.

Part of my problem was that I was putting parenthesis where they shouldn't go.

So
[CODE]javascript:(document.write(document.forms[0].elements[0].name))[/CODE]
should be
[CODE]javascript:document.write(document.forms[0].elements[0].name)[/CODE]
×

Success!

Help @joecap5 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...