Ad

VBA Excel Run Javascript Form Event

- 1 answer

I’ve already tried to get the element by id, however, the html does not include it. As shown below, this is the script for the drop down that I am trying to change automatically. It will change the name with

appIE.Document.getElementById("supervisor").Value = "Sup_name"

However, it doesn’t fire the event that generates a list of people.

The top of the form also includes <form id='filterform' action="javascript:void(0);">

The JavaScript containing the function I need to call is below.

<script type="text/javascript">

    $(function() {
        $('#supervisor').change(function() {
            document.getElementById('results').innerHTML = '<img src="/img/busy.gif" />';
            var str = $('#filterform').serializeArray();
            $.ajax({
                url: 'ajax.php?p=agentrosters&mode=1&field=supervisor',
                type: 'POST',
                data: str,
                success: function(j) {
                    //alert(j);
                    document.getElementById('results').innerHTML = j;
                    document.getElementById('lastsearch').value = 'supervisor';
                    resetscript('supervisor');
                },
                failure: function() {
                    document.getElementById('results').innerHTML = 'There has been an error, please try again';
                    resetscript('null');
                }
            })
        })
    })

</script>

Any Ideas on how I can get this to work?

Ad

Answer

If the element is part of a form you may to submit the form, alternatively you can use the onchange event on the element itself. So you may want to change

appIE.Document.getElementById("supervisor").Value = "Sup_name"

to

With appIE.document.getElementById("supervisor") .Value = "Sup_name" .onchange End with

And if it is part of a form change the ".onchange" to ".parentElement.Submit"

This worked for me.

Ad
source: stackoverflow.com
Ad