0
votes

We're creating a HTA file so withe the information the user has input, we can automate the process of logging a ticket. The user will input the information in the HTA form and click Submit. This will then open a link in IE, input the data from the HTA to the relevant fields and then automatically click the Submit button at the end of the page.

The majority of it works so far but I'm unable to automate the Submit action. I've checked various forums but haven't been able to get this working with any suggestions so far. I'm just looking for a way to automate clicking the submit button in the IE window.

There are 3 buttons on the IE page and I'm not sure how to specify I want to click submit.

New to VBScript so any help is much appreciated.

<input value="Reset" onclick="return myReset();" class="secondary" type="button">
<input value="Add to a Bundle" onclick="return myAddRequisition();" class="secondary" name="submitorderform" type="submit">
<input value="Submit " onclick="return myOrderNow();" class="primary" name="submitorderform" type="submit">
1
Edited for clarity. Looking to automate the process of clicking submit in IE window. - 6TTW014

1 Answers

0
votes

I think the code that you posted is kind of weird, since it has two buttons with the same name.
I assume that the webpage in IE to which the information is to be sent contains only one form.
I also assume that an instance of IE automation object is stored in IE variable. After you filled out the form via your HTA programmatically, if you want to simulate a click on the button "Add to bundle" , use the code below:

var frm = IE.document.forms[0];
for (var i = 0;i < frm.elements.length;i++)
    if (frm.elements[i].type == "submit" && frm.elements[i].value == "Add to a Bundle")
        frm.elements[i].click();

Or, if you want to click on the button "Submit ", you can use the code above, but be sure to replace "Add to a Bundle" with "Submit ".

Edit: In VBScript, you can use the code below:

Dim frm, i
Set frm = IE.document.forms.item(0)
For i = 0 to frm.elements.length - 1
    If frm.elements.item(i).value = "Add to a Bundle" And frm.elements.item(i).type = "submit"  Then
        frm.elements.item(i).click
    End If
Next

Edit 2: According to your comments, i guess you don't wait for your webpage until it is completely loaded. Thus, you get an Unspecified Error. To solve this problem, you should set an interval to repeatedly check if IE.ReadyState equals 4. To do so, use the code below after calling Navigate method of IE:

Dim interval
interval = window.setInterval(GetRef("fillOutForm"), 1000)

Sub fillOutForm()
    If IE.ReadyState = 4 Then
        window.clearInterval interval
        'Here place code that fills out the form in the webpage and submits it.
    End If
End Sub

As you can see, you should call setInterval method and set the first parameter to a function pointer. Use the GetRef function to obtain a function pointer. In the code that I sent, I passed a pointer to the subroutine fillOutForm. So this subroutine will be called every 1 second. In this subroutine, you check if IE.ReadyState equals 4 then you fill out the form and submit it.