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>
Shan Atif
1471 silver badge14 bronze badges
asked Jun 10, 2019 at 9:29
2
  • i think your datatype must be select Commented Jun 10, 2019 at 9:35
  • i added <item name="formElement" xsi:type="string">select</item> Commented 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 );
 });
});
answered Jun 10, 2019 at 9:53
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]] Commented Jun 10, 2019 at 9:57
  • try like $('select[name="slider_details[slider_location]"]').val(); Commented Jun 10, 2019 at 10:05
  • i want to get value in initalize function there it is not working otherwise its working well Commented Jun 10, 2019 at 11:04
  • can you check updated answer Commented Jun 10, 2019 at 11:35

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.