Excel VBA to click submit javascript

532 views Asked by At

I cannot figure out how to fire event to enter data into input box. There appears to be no id name associated with javascript in which to click. I wonder if it is necessary to simulate a Submit of the form. But there is no html submit and instead there is a javascript submit section. How does VBA fire the submit?

<form method="post" action="AddDeductions?formId=ccf28bb7-e24a-46f2-ae7e-a7016521654c&amp;locationCd=001&amp;regionCode=MAR&amp;busClass=017" id="EasyTax">
<div class="aspNetHidden">
<input type="hidden" name="1_Taxes_ExpandState" id="1_Taxes_ExpandState" value="unnnnnunnunnnnununnunnnnnnunnnnnunnnnunnn" />
<input type="hidden" name="1_Taxes_SelectedNode" id="1_Taxes_SelectedNode" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

   <table class="webGrid" data-swhgajax="true" data-swhgcontainer="gridContent" data-swhgcallback="gridChangeCallBack">
<tr class="alt">
  <td class="amount"><span> <span id="spanDeduction_534"></span> 
  <input class="DeductionAmt" id="Deduction_534" maxlength="13" name="Deduction_534" placeholder="0.00" style="text-align: right;" type="text" value="0.00" />
  <label id="forTxtxAmt" for="deduction_534" hidden="hidden">TPT Tax</label></span></td>
</tr>
</table>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['EasyTax'];
if (!theForm) {
    theForm = document.EasyTax;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

The following VBA code does not work. The 99 is displayed but "not submitted" in the input box.

Set xcc = IE.document.getElementById("Deduction_534")
Set evt = IE.document.createEvent("HTMLEvents") 
evt.initEvent "change", False, True
xcc.Focus 'this works and the input box is focused
xcc.click 'not sure if this works as I don't see the cursor placed on the box
xcc.Value = 99 'this shows up in input box
xcc.dispatchEvent evt 'does nothing
ie.document.forms("EasyTax").submit 'submit action occurs but no data is submitted

1) Is there any way to fire an event to submit the 99?

2) How do I run the javascript code in the CDATA section using VBA to submit?

0

There are 0 answers