2

I am lost, please take a look at http://www.austrokamin.at/edelstahlkamine/edelstahlkamin-doppelwandig/bodenplatte-dw.html

I need to set the two dropdowns with jQuery. For example:

jQuery('#product-options-wrapper .input-box select').eq(0).prop('selectedIndex', 2);

No Problem so far. But now some event handler(s) must be triggered so that the second dropdown is activated.

When i select the element in Firebug and type getEventListeners(0ドル) it tells me "blur", "focus" and "change"

I fired all of these events in the console with:

jQuery('#product-options-wrapper .input-box select').eq(0).focus();
jQuery('#product-options-wrapper .input-box select').eq(0).change();
jQuery('#product-options-wrapper .input-box select').eq(0).blur();

but nothing seems to have effect. Can anyone help me please.

asked Dec 17, 2014 at 9:29

1 Answer 1

2

You can use this js code and then just call $$('#product-options-wrapper .input-box select')[0].simulate('change')

[EDIT]
here is the original code. In case it gets removed from github.
The code is not mine. Kudos to kangax

/**
 * Event.simulate(@element, eventName[, options]) -> Element
 * 
 * - @element: element to fire event on
 * - eventName: name of event to fire (only MouseEvents and HTMLEvents interfaces are supported)
 * - options: optional object to fine-tune event properties - pointerX, pointerY, ctrlKey, etc.
 *
 * $('foo').simulate('click'); // => fires "click" event on an element with id=foo
 *
 **/
(function(){
 var eventMatchers = {
 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
 'MouseEvents': /^(?:click|mouse(?:down|up|over|move|out))$/
 }
 var defaultOptions = {
 pointerX: 0,
 pointerY: 0,
 button: 0,
 ctrlKey: false,
 altKey: false,
 shiftKey: false,
 metaKey: false,
 bubbles: true,
 cancelable: true
 }
 Event.simulate = function(element, eventName) {
 var options = Object.extend(defaultOptions, arguments[2] || { });
 var oEvent, eventType = null;
 element = $(element);
 for (var name in eventMatchers) {
 if (eventMatchers[name].test(eventName)) { eventType = name; break; }
 }
 if (!eventType)
 throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported');
 if (document.createEvent) {
 oEvent = document.createEvent(eventType);
 if (eventType == 'HTMLEvents') {
 oEvent.initEvent(eventName, options.bubbles, options.cancelable);
 }
 else {
 oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView, 
 options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
 options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element);
 }
 element.dispatchEvent(oEvent);
 }
 else {
 options.clientX = options.pointerX;
 options.clientY = options.pointerY;
 oEvent = Object.extend(document.createEventObject(), options);
 element.fireEvent('on' + eventName, oEvent);
 }
 return element;
 }
 Element.addMethods({ simulate: Event.simulate });
})()
answered May 12, 2015 at 11:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.