-2

I have this thirs-part website, where if I select one country on the right

(as you can see in the video: https://i.gyazo.com/3a22aabb576f1e43040dae82204bb883.mp4 )

it changes shipping fees (in violet).

If instead, I use js ( from the chrome console for instance) to select one country using

 document.getElementById("order").value =  "IT";

it will select the country but the fees on the don't change. There is a way to let it works using javascript?

I have tried to also perform a click by

document.getElementById("order").click();

after selecting a value but it doesn't work.

Marià
  • 255
  • 2
  • 12

1 Answers1

0

Trigger the onchange after changing the value - you can do that from the console or from a chrome extension

document.getElementById("order").value = "IT";
document.getElementById("order").onchange();
<select id="order" onchange="alert(this.value)">
  <option value="">Please select</option>
  <option value="IT">Italy</option>
</select>

If the site has jQuery, use $("#order").val("IT").change()

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • the website is third-par i can't edit the html part i just want to trigger the change when i use the getlelementbyyd.value="IT"; – Marià Sep 27 '18 at 16:28
  • You can do that without changing the site. `document.getElementById("order").value = "IT"; document.getElementById("order").onchange();` - the select has an onchange already – mplungjan Sep 27 '18 at 16:32
  • If the site has jQuery, use `$("#order").val("IT").change()` – mplungjan Sep 27 '18 at 16:34
  • i cannot use jquery unfrtunatly i have tryed whit the occhange() but the console gives me this error : Uncaught TypeError: document.getElementById(...).onchange is not a function at :1:50 – Marià Sep 27 '18 at 16:41
  • if `document.getElementById("order").value = "IT";` works then it is very strange that it does not allow onchange – mplungjan Sep 27 '18 at 16:42
  • And I did not mean YOU should use jQuery, just call it if it is present in the site. – mplungjan Sep 27 '18 at 16:43
  • ok i have tried the jquery stuff and it works... the problem is i'm in a chorme extension so i can't use jquery as i know , while the onchange says that is not a function – Marià Sep 27 '18 at 16:46
  • Of course you can use jQuery if the page you are on has loaded and is using it. You can also load jQuery if it is not loaded by the page – mplungjan Sep 27 '18 at 18:43