On Aug 19, 9:46*am, brad <byte8b...@gmail.comwrote:
Hi there,
New to javascript. Question about populating a form on a webpage that I
do not control. I can see the field names and ids and currently have a
button that onsubmit opens the page in a new window that contains the
form I'd like to populate. Any tips on how to populate the form. We're
trying to make it easier for users to submit it... no bots as it has a
captcha.
Just grab a reference to the DOM element you're after and set the
'value' attributes.
Look into getElementsByName() and getElementById(). The first returns
an array (NodeSet actually) so if it is the only element with that
'name' in your document then you would have to say something like:
document.getElementsByName('someName')[0].value = "some value"
If you could get an element reference starting at the form, you could
iterate through the form using nextChild and/or nextSibling and set
all the values to what you like.
Oh, and one more thing I guess, since you are opening this up in a new
window, you must reference the correct document. If your script is in
the new window, you could just say "document.", but if you are doing
it from the parent window, use the reference returned when your create
the child window.
And if you're opening the document in a frame, you must also consider
this when trying to get a reference to an element. And everything may
fail anyway, depending on how forms loaded in a frame from another
domain are handled when submitted. I'm not sure to be honest with you.
http://developer.mozilla.org/en/docs...lement#Methods http://developer.mozilla.org/en/docs/DOM:window.frames
slightly off topic since this can't be used by your users, but:
http://en.wikipedia.org/wiki/Greasemonkey
Good luck!