1

I need to get selected value from select field using jquery in magento

<field name="slider_location">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Vendor_Modulename/js/form/element/containers</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Display On</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataScope" xsi:type="string">slider_location</item>
                </item>
            </argument>
        </field>
  • i think your datatype must be select – Rk Rathod Jun 10 '19 at 9:35
  • i added <item name="formElement" xsi:type="string">select</item> – Waqar Ali Jun 10 '19 at 9:47
0

You can simply get it with the select name attribute

$('select[name=general[slider_location]]').val();

Note: general → is the fieldset name, change it accordingly.

You can bind the it on change event:

$(document).ready(function(){
  $('select[name="slider_details[slider_location]"]').change(function(){
    alert( this.value );
  });
});
  • i added jQuery('select[name=slider_details[slider_location]]').val(); got a console error syntax error, unrecognized expression: select[name=slider_details[slider_location]] – Waqar Ali Jun 10 '19 at 9:57
  • try like $('select[name="slider_details[slider_location]"]').val(); – fmsthird Jun 10 '19 at 10:05
  • i want to get value in initalize function there it is not working otherwise its working well – Waqar Ali Jun 10 '19 at 11:04
  • can you check updated answer – fmsthird Jun 10 '19 at 11:35

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.