0

I am trying to execute a javascript function using VBA but without success.

I select an item in the list box.

My goal: refresh the result after item selected.

VBA:

IEdoc_NEW2.getElementById("native_dropdown_selected_size_name").selectedIndex = 1
Call IEdoc_NEW2.parentWindow.execScript("dummySubmitButton()", "JavaScript")

HTML:

<select name="dropdown_selected_size_name" tabindex="-1" class="a-native-dropdown" id="native_dropdown_selected_size_name" autocomplete="off" data-a-touch-header="Taille">
  <option id="native_size_name_-1" value="-1" selected="" data-a-id="size_name_-1">Sélectionner</option>
  <option class="dropdownAvailable" id="native_size_name_0" value="0,B07DHJZSB3" data-a-id="size_name_0" data-a-html-content="S" data-a-css-class="dropdownAvailable">
    S </option>
  <option class="dropdownUnavailable" id="native_size_name_1" value="1,B07DHKZM7P" data-a-id="size_name_1" data-a-html-content="M" data-a-css-class="dropdownUnavailable">
    M
  </option>
  <option class="dropdownUnavailable" id="native_size_name_2" value="2,B07DHK697N" data-a-id="size_name_2" data-a-html-content="L" data-a-css-class="dropdownUnavailable">
    L
  </option>
</select>

JavaScript:

if (typeof(TwisterNonJs) == 'undefined') {
  window.TwisterNonJs = {};
  TwisterNonJs.handleDropDown = [];
}
TwisterNonJs.handleDropDown[1] = function() {
  var twisterUpdateButton = "submit.twisterUpdateButton_1"
  document.getElementById("dummySubmitButton").setAttribute("name", twisterUpdateButton);
  document.forms['twister'].submit();
};
document.getElementById("native_dropdown_selected_size_name").onchange = function() {
  TwisterNonJs.handleDropDown[1]();
};

But this isn't working.

1 Answer 1

1

Try onchange fireEvent

IEdoc_NEW2.getElementById("native_dropdown_selected_size_name").FireEvent "onchange"

You could also try adding an event then firing it

Dim evt As Object
Set evt = .document.createEvent("HTMLEvents")
evt.initEvent "change", True, False

IEdoc_NEW2.querySelector("#native_dropdown_selected_size_name").dispatchEvent evt
Sign up to request clarification or add additional context in comments.

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.