1

I am trying to navigate through a from in internet explorer via Excel VBA.

This is the VBA code I use to do it, which works fine:

IEDoc.getElementById("PROGRAMME-select").selectedindex = 1

However, for another dropdown menu, which after a selection dynamically changes the rest of the form, the code from above doesn't work. I assume it's due to the javascript of the webpage. This is the HTML code of it:

<DIV id=Q_FORMAT jQuery1441195683481="347">
<INPUT id=Q_FORMAT_data value='{"name":"FORMAT","inputType":"select"}' type=hidden name=Q_FORMAT_data> 
<DIV style="DISPLAY: block" id=FORMAT-label>
<LABEL><B>Format :</B> </LABEL></DIV><SELECT id=FORMAT-select name=FORMAT-select>
<OPTION id=FORMAT_EMPTY_OPTION value=EMPTY_OPTION></OPTION>
<OPTION id=FORMAT_YES value=FORMAT_YES name="FORMAT_YES">Non-Standard</OPTION>
<OPTION id=FORMAT_NO selected value=FORMAT_NO name="FORMAT_NO">Standard</OPTION></SELECT> </DIV>

Does anyone know how to trigger the javascript in order to have the rest of the form be updated by the selection I am trying to do? Or possibly it's a completely different issue I am facing here?

2 Answers 2

1

can you try using the fireevent method for the listbox and try once ?

eg code:

IEDoc.getElementById("PROGRAMME-select").selectedindex = 2

IEDoc.getElementById("PROGRAMME-select").fireevent "Onchange"
Sign up to request clarification or add additional context in comments.

6 Comments

I tried this but nothing happens. The dropdown menu doesn't change. I saw someone on stackoverflow.com link who has the same issue and solved it by this: IEDoc.parentWindow.execScript ("jQuery('#type').val('2');jQuery('#type').trigger('chosen:updated');") But I don't know how I can modify this to help my case actually.
just use this line of code after your code where u set the value, IEDoc.getElementById("PROGRAMME-select").fireevent "Onchange"
I have tried it already but nothing happends. The index doesn't change, whatever I set it to. Is it maybe bcs there is no "onchange" event in the HTML?
instead of selection by the index, can you try to select by the text displayed? something like this below, 'Set weblist = objDocument.getElementsByTagName("Select") For Each btnSelect In weblist If Trim(btnSelect.Name) = "FORMAT-select" Then Set listoption = btnSelect.getElementsByTagName("Option") For Each btnOption In listoption If UCase(Trim(btnOption.Text)) = UCase("Non-Standard") Then btnOption.Selected = True btnSelect.fireevent "Onchange" Exit For End If Next end if Next'
hm no :/ doesn't seem to get it going. It runs through but doesn't change value. Do you think the jQuery needs to be triggered somehow?
|
0

After the form changes it has new html on the document. Instead of using IEDoc - which you probably set before the change - just use ie.document.getElementById("NEW NAME HERE").selectedindex = 1

(This assumes that you set your instance of msie to ie. Just use whatever variable you gave to this instance and .document will always give you the most recent version after any javascript changes. The form ID's might have changed also so you might try listing all ID's in the form again just to see.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.