By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

JavaScript and Automating form submission

P: n/a
weird subject - i hope more than just one curious regular will hear me out.
:)

ok, i've got a bit of a big problem, and i need answers as soon as
possible.

i know this forum is meant for web developers, but is relevant discussion.
i'm not OT here unless someone thinks i'm trolling (which i'm not,
obviously). then i'll disappear and never show my face again. :P

we are automating form submission using the MS IE 5 DOM through the
InternetExplorer object and have run against two major roadblocks: both of
which involve JavaScript and the DOM exposed in Internet Explorer, so i
hope someone can help out here.

first, and easiest, we will need to be able to upload files assosciated
with this form sumbission. we'd like to automate it, like everything else.
my question here is: how do we assign a file to an input field of type
"file" to upload it?

second, and more difficult: the forms use a validation script that ensures
proper content in the form. it's difficult to ensure all our data will
pass the validation, so we would like to be able to flag errors as they
come. the validation script scans the contents of the form and calls
window.alert() when an error is detected (i.e., missing data or incorrect
data type). after the alert(), focus() is given to the first field in
question. this problem is twofold: we need to detect the alert(), AND we
need to know which input field has focus. so how do we trap the alert(),
and how do we detect which field got focus()? (we do, in fact, have a
complete list of possible fields that may gain focus.)

any help would be greatly appreciated, even if it's "go away and ask this
in microsoft.public.inetsdk.*!" (unfortunately, that's the first place i
tried, and either no one knows or no one wants to answer.)

--
Charles Banas
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In article <op**************@news.cableone.net>, Charles Banas
<no****@myplace.net> writes:

weird subject - i hope more than just one curious regular will hear me out.
:)

ok, i've got a bit of a big problem, and i need answers as soon as
possible.

i know this forum is meant for web developers, but is relevant discussion.
i'm not OT here unless someone thinks i'm trolling (which i'm not,
obviously). then i'll disappear and never show my face again. :P

we are automating form submission using the MS IE 5 DOM through the
InternetExplorer object and have run against two major roadblocks: both of
which involve JavaScript and the DOM exposed in Internet Explorer, so i
hope someone can help out here.

first, and easiest, we will need to be able to upload files assosciated
with this form sumbission. we'd like to automate it, like everything else.
my question here is: how do we assign a file to an input field of type
"file" to upload it?
In normal security environments, you don't. Its off-limits to scripting. An
ActiveX *might* be able to, but never seen one that would that didn't require
down in the dirt, have your way with my PC security settings.
second, and more difficult: the forms use a validation script that ensures
proper content in the form. it's difficult to ensure all our data will
pass the validation, so we would like to be able to flag errors as they
come. the validation script scans the contents of the form and calls
window.alert() when an error is detected (i.e., missing data or incorrect
data type). after the alert(), focus() is given to the first field in
question. this problem is twofold: we need to detect the alert(), AND we
need to know which input field has focus. so how do we trap the alert(),
and how do we detect which field got focus()? (we do, in fact, have a
complete list of possible fields that may gain focus.)

any help would be greatly appreciated, even if it's "go away and ask this
in microsoft.public.inetsdk.*!" (unfortunately, that's the first place i
tried, and either no one knows or no one wants to answer.)


Pass a reference to the element to your function. If you are calling the
function from each field, onchange, instead of onchange="someFunction()", use
onchange="someFunction(this)" and it will tell the function, anonymously, what
element called it:

function someFunction(formField){
//validation here
if (passes){

}
else{
window.alert(.......)
formField.focus()
}
}

If the validation function is being called by the onsubmit handler, then it has
to go through all fields, and should know when the field fails, and be able to
know what field needs focus.

If none of this applies, doesn't help, or confuses you, post a very brief
sample page that shows the basics of the page you are actually using. URL
preferred to code.
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Jul 20 '05 #2

P: n/a
On 29 Jul 2003 00:08:21 GMT, HikksNotAtHome <hi************@aol.com> wrote:
In normal security environments, you don't. Its off-limits to scripting.
An
ActiveX *might* be able to, but never seen one that would that didn't
require
down in the dirt, have your way with my PC security settings.
since we don't have time to develop such a plugin, do you know of one we
could use? or is it as impossible as it looks?

Pass a reference to the element to your function. If you are calling the
function from each field, onchange, instead of onchange="someFunction()",
use
onchange="someFunction(this)" and it will tell the function, anonymously,
what
element called it:
i guess i wasn't clear enough about it - this isn't our page we're
automating, so i can't really change anything on the page itself. :) it's
being done remotely though the InternetExplorer automation object. (which
really isn't all that good for automation.)
function someFunction(formField){
//validation here
if (passes){

}
else{
window.alert(.......)
formField.focus()
}
}
that is similar to how it's handled, but see attached the source.
information that could be considered "sensitive" has been changed. the
page itself remains unchanged.
If the validation function is being called by the onsubmit handler, then
it has
to go through all fields, and should know when the field fails, and be
able to
know what field needs focus.
unfortunately, that doesn't apply since you're assuming something i didn't
clarify enough. :P
If none of this applies, doesn't help, or confuses you, post a very brief
sample page that shows the basics of the page you are actually using. URL
preferred to code.


this is the most "brief" of the pages in question, and it should give you a
good idea what i'm dealing with.

the links are intentionally broken and names removed to protect the victim
(and possibly my job). :P
Jul 20 '05 #3

P: n/a
On Mon, 28 Jul 2003 16:50:20 -0600, Charles Banas <no****@myplace.net>
wrote:
i know this forum is meant for web developers, but is relevant discussion.
i'm not OT here unless someone thinks i'm trolling (which i'm not,
obviously). then i'll disappear and never show my face again. :P
I understood it was meant for discussing javascript, but what the
heck...
first, and easiest, we will need to be able to upload files assosciated
with this form sumbission. we'd like to automate it, like everything else.
my question here is: how do we assign a file to an input field of type
"file" to upload it?
just do fileelRef.value="moomin..." in a secure environment this
should be no problem.
second, and more difficult: the forms use a validation script that ensures
proper content in the form. it's difficult to ensure all our data will
pass the validation, so we would like to be able to flag errors as they
come. the validation script scans the contents of the form and calls
window.alert() when an error is detected (i.e., missing data or incorrect
data type). after the alert(), focus() is given to the first field in
question. this problem is twofold: we need to detect the alert(), AND we
need to know which input field has focus. so how do we trap the alert(),
and how do we detect which field got focus()?


Simply override the alert method with your own, which looks to see
what the message was. to catch which has focus, all I can see is to
overide each elements focus method... but it might be easier simply to
change the validation function to tell you directly...

How to override the functions and everything - look at
http://jibbering.com/snufkin/ which does it.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4

P: n/a
On Tue, 29 Jul 2003 04:00:58 GMT, Jim Ley <ji*@jibbering.com> wrote:

How to override the functions and everything - look at
http://jibbering.com/snufkin/ which does it.
wait - are you sure that's what that page talks about?
Jim.


--
Charles Banas
Jul 20 '05 #5

P: n/a
On Tue, 29 Jul 2003 10:11:38 -0600, Charles Banas <no****@myplace.net>
wrote:
sorry - to clarify, i'm doing this in Access 97 through the
InternetExplorer "automatin" object. maybe i shouldn't have put
"JavaScript" in the subject....


Automating it with JS or VBA or whatever, the Object Model is the
same, and snufkin shows how to override window methods (not
window.alert specifically) but others to achieve what you want, making
them non-interactive, if you look at Snork an even older piece of code
knocking about on my site, I think you'll even see alert being
over-ridden.

Doing what you want is simple automating IE from JS, I'm sure it will
be simple from VBA too, but VBA is just a muppet language.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #6

P: n/a
On Tue, 29 Jul 2003 20:03:16 GMT, Jim Ley <ji*@jibbering.com> wrote:
On Tue, 29 Jul 2003 10:11:38 -0600, Charles Banas <no****@myplace.net>
wrote:
sorry - to clarify, i'm doing this in Access 97 through the
InternetExplorer "automatin" object. maybe i shouldn't have put
"JavaScript" in the subject....


Automating it with JS or VBA or whatever, the Object Model is the
same, and snufkin shows how to override window methods (not
window.alert specifically) but others to achieve what you want, making
them non-interactive, if you look at Snork an even older piece of code
knocking about on my site, I think you'll even see alert being
over-ridden.

Doing what you want is simple automating IE from JS, I'm sure it will
be simple from VBA too, but VBA is just a muppet language.

Jim.


i'll look it over more closely, then.

thanks

--
Charles Banas
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.