Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

html - execute javascript function using VBA

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...