Consulting

Results 1 to 4 of 4

Thread: Hitting Submit using VBA in IE

  1. #1

    Hitting Submit using VBA in IE

    Hello all,

    I am having trouble with getting a javascript function to execute in vba. My script so far takes me to the website, logs in, goes to the correct page, and changes the drop down menu to the correct option. On this dropdown menu page there is no submit button until the drop down changes and I use .FireEvent (onchange) to make the submit button appear. The trouble I am having is with pressing the submit button which will open the new window. It seems that the submit is in a Function which I do not know how to manipulate in vba.

    The script that shows where I run the javascript to get the submit button to appear is shown below.

    With .document
                         ' select shareholding
                        Set SecName = .getElementsByName("ctl00$ContentPlaceHolder1$RptSel$ddlReport")
                        SecName(0).Value = "279"
                        Set objURLpage = ie.document
                        Set objSELECTelement = objURLpage.getElementById("ctl00$ContentPlaceHolder1$RptSel$ddlReport")
                        objSELECTelement.selectedIndex = 2
                        objSELECTelement.FireEvent ("onchange")
                        With appIE
     End With
    This is the source code showing the javascript which references a doPostBack

    onchange="javascript:setTimeout('__doPostBack(\'ctl00$ContentPlaceHolder1$RptSel$ddlReport\',\'\')', 0)" id="ctl00_ContentPlaceHolder1_RptSel_ddlReport">

    This is the source code for the post back function which I assume is what I need to hit submit.

    <
    
    scripttype="text/javascript">
    
    //<![CDATA[
    
    var
     theForm = document.forms['aspnetForm'];
    
    if
     (!theForm) {
    
        theForm = document.aspnetForm;
    
    }
    
    function
     __doPostBack(eventTarget, eventArgument) {
    
        
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
    
            theForm.__EVENTTARGET.value = eventTarget;
    
            theForm.__EVENTARGUMENT.value = eventArgument;
    
            theForm.submit();
    
        }
    
    }
    
    Any help with this would be greatly appreciated. If any more information is needed please do let me know and I will provide what I can.

    Thanks!

  2. #2
    if you can access the form element, you could try to submit the form, or you could try posting the forms action if it is javascript

  3. #3
    Quote Originally Posted by westconn1 View Post
    if you can access the form element, you could try to submit the form, or you could try posting the forms action if it is javascript
    I tried multiple ways to submit the form but have been unsuccessful so far. Not exactly sure what you mean by posting the forms action however this was also a part of the source code it it helps any:

    <
    
    formname="aspnetForm"method="post"action="reportselection.aspx?ProgramID=230"id="aspnetForm">
    
    <
    div>
    
    <
    inputtype="hidden"name="ctl00_RadScriptManager1_TSM"id="ctl00_RadScriptManager1_TSM"value=""/>
    
    <
    inputtype="hidden"name="__EVENTTARGET"id="__EVENTTARGET"value=""/>
    
    <
    inputtype="hidden"name="__EVENTARGUMENT"id="__EVENTARGUMENT"value=""/>
    
    <
    inputtype="hidden"name="__LASTFOCUS"id="__LASTFOCUS"value=""/>
    
    <
    inputtype="hidden"name="__VIEWSTATE"id="__VIEWSTATE"

  4. #4
    formname="aspnetForm"method="post"action="reportselection.aspx?ProgramID=230"id="aspnetForm">
    the forms action is described

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •