JavaScript and Automating form submission

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Charles Banas

    JavaScript and Automating form submission

    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
    InternetExplore r 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.publi c.inetsdk.*!" (unfortunately, that's the first place i
    tried, and either no one knows or no one wants to answer.)

    --
    Charles Banas
  • HikksNotAtHome

    #2
    Re: JavaScript and Automating form submission

    In article <oprs1lp6awccvy 18@news.cableon e.net>, Charles Banas
    <none4u@myplace .net> writes:
    [color=blue]
    >
    >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
    >InternetExplor er 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?[/color]

    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.
    [color=blue]
    >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.publi c.inetsdk.*!" (unfortunately, that's the first place i
    >tried, and either no one knows or no one wants to answer.)[/color]

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

    function someFunction(fo rmField){
    //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.

    Comment

    • Charles Banas

      #3
      Re: JavaScript and Automating form submission

      On 29 Jul 2003 00:08:21 GMT, HikksNotAtHome <hikksnotathome @aol.com> wrote:
      [color=blue]
      > 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.
      >[/color]
      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?
      [color=blue]
      >
      > Pass a reference to the element to your function. If you are calling the
      > function from each field, onchange, instead of onchange="someF unction()",
      > use
      > onchange="someF unction(this)" and it will tell the function, anonymously,
      > what
      > element called it:
      >[/color]
      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 InternetExplore r automation object. (which
      really isn't all that good for automation.)
      [color=blue]
      > function someFunction(fo rmField){
      > //validation here
      > if (passes){
      >
      > }
      > else{
      > window.alert(.. .....)
      > formField.focus ()
      > }
      > }
      >[/color]
      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.
      [color=blue]
      > 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.
      >[/color]
      unfortunately, that doesn't apply since you're assuming something i didn't
      clarify enough. :P
      [color=blue]
      > 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.[/color]

      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

      Comment

      • Jim Ley

        #4
        Re: JavaScript and Automating form submission

        On Mon, 28 Jul 2003 16:50:20 -0600, Charles Banas <none4u@myplace .net>
        wrote:[color=blue]
        >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[/color]

        I understood it was meant for discussing javascript, but what the
        heck...
        [color=blue]
        >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?[/color]

        just do fileelRef.value ="moomin..." in a secure environment this
        should be no problem.
        [color=blue]
        >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()?[/color]

        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.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • Charles Banas

          #5
          Re: JavaScript and Automating form submission

          On Tue, 29 Jul 2003 04:00:58 GMT, Jim Ley <jim@jibbering. com> wrote:
          [color=blue]
          >
          > How to override the functions and everything - look at
          > http://jibbering.com/snufkin/ which does it.
          >[/color]
          wait - are you sure that's what that page talks about?
          [color=blue]
          > Jim.[/color]



          --
          Charles Banas

          Comment

          • Jim Ley

            #6
            Re: JavaScript and Automating form submission

            On Tue, 29 Jul 2003 10:11:38 -0600, Charles Banas <none4u@myplace .net>
            wrote:
            [color=blue]
            >sorry - to clarify, i'm doing this in Access 97 through the
            >InternetExplor er "automatin" object. maybe i shouldn't have put
            >"JavaScript " in the subject....[/color]

            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.javas cript FAQ - http://jibbering.com/faq/

            Comment

            • Charles Banas

              #7
              Re: JavaScript and Automating form submission

              On Tue, 29 Jul 2003 20:03:16 GMT, Jim Ley <jim@jibbering. com> wrote:
              [color=blue]
              > On Tue, 29 Jul 2003 10:11:38 -0600, Charles Banas <none4u@myplace .net>
              > wrote:
              >[color=green]
              >> sorry - to clarify, i'm doing this in Access 97 through the
              >> InternetExplore r "automatin" object. maybe i shouldn't have put
              >> "JavaScript " in the subject....[/color]
              >
              > 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.[/color]

              i'll look it over more closely, then.

              thanks

              --
              Charles Banas

              Comment

              Working...