JavaScript and Automating form submission

C

Charles Banas

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

Charles Banas

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
 
J

Jim Ley

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

Jim Ley

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

Charles Banas

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
 

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,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top