I made a script that selects an option from a dropdown. The dropdown has onchange trigger and it trigger correctly when i run the script as a snippet (in a sandbox environment), but when i active the script on my Magento site the onchange script doesn't trigger?

This is my code:

function selectItemByValue(dropValg, value) {
  var denne = document.getElementById(dropValg);
  denne.value = value;

  <li onclick="selectItemByValue('bundle-option-132', 700)"> Click to change</li>

<select onchange="alert('Content changed')" id="bundle-option-132" name="bundle_option[132]" class="bundle-option-132 bundle-option-select change-container-classname" wtx-context="276DE744-A364-4DD3-AEFC-0D9F9A9AAE19">
  <option value="">Udvælg...</option>
  <option value="875">Bianco</option>
  <option value="695">T400</option>
  <option value="697">T402</option>
  <option value="698">T403</option>
  <option value="699">T404</option>
  <option value="700">T405</option>
  <option value="702">T407</option>
  <option value="703">T408</option>
  <option value="704">T409</option>
  <option value="705">T410</option>

I made a code snippet here: https://www.w3schools.com/code/tryit.asp?filename=FJWGP8WR16DD

On my Magento site the onchange script looks like this: onchange="bundle.changeSelection(this)" but if i replace this with onchange="alert(Something)" the script still doesn't trigger.

I'm using an extension called OptionBundle that needs the onchange trigger to calculate the content of the next dropdown. The onchange trigger works when choosing an option manually from the dropdown but not when choosing an option with JS?

The only other script I can see that's monitoring change on this dropdown is prototype.js, but I just can't see why this would conflict with my script?

  • can you please add your magento code? Sep 25, 2017 at 20:47
  • @AbhishekPanchal how much code? The above example is the code used on my site except the onchange trigger which is onchange="bundle.changeSelection(this) and not the alert used in the example. Do you mean the PHP code? I'm not changing anything in the PHP? It's all JavaScript, but something is blocking/overriding the onchangetrigger? Sep 25, 2017 at 21:14

1 Answer 1


you can try :

$('#bundle-option-132').bind('change', function (e) {
//your code here

Note: $ = jQuery

  • Hi. I'm not quite sure on how to use your example? I've tried: $( document ).ready(function() { $('#bundle-option-132').bind('change', function() { alert('Yes') }); }); but it haves the same problem. It only triggers when i manually click the dropdown on choose an option. When I choose an option from the dropdown with JavaScript, then content of the dropdown changes (it shows the right option), but no onchange script is triggered including the Jquery .bind script. No onchange or change event listener seems to register when content is changed by JS? Sep 27, 2017 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.