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>
2
  • i think your datatype must be select Jun 10, 2019 at 9:35
  • i added <item name="formElement" xsi:type="string">select</item>
    – Waqar Ali
    Jun 10, 2019 at 9:47

1 Answer 1

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 );
  });
});
4
  • 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, 2019 at 9:57
  • try like $('select[name="slider_details[slider_location]"]').val();
    – fmsthird
    Jun 10, 2019 at 10:05
  • i want to get value in initalize function there it is not working otherwise its working well
    – Waqar Ali
    Jun 10, 2019 at 11:04
  • can you check updated answer
    – fmsthird
    Jun 10, 2019 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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