0

I have a wordpress theme using autocomplete suggestion by getJSON,suggestion call into a drop down option like below

enter image description here

And the inspect view is below enter image description here

I want save the ID and value of the selected option into a variable, How can i do it please help.

Thanks

NaFi
  • 81
  • 1
  • 13
  • 1
    Check the documentation of the select plugin you're using. I would imagine it has a method to build a string/object/array from the selected values – Rory McCrossan Oct 17 '18 at 13:19

1 Answers1

1

If you are using jquery then you can use attr()

Check the documentation http://api.jquery.com/attr/

try this code:

$('#element option:selected').attr('id');
tonoslfx
  • 3,422
  • 15
  • 65
  • 107
  • Thanks , but can it called directly via a JS because string is controlled by a java script – NaFi Oct 18 '18 at 05:15
  • there are many example on the site you can find. https://stackoverflow.com/questions/11957677/html-how-to-get-custom-attribute-of-option-tag-in-dropdown – tonoslfx Oct 18 '18 at 09:56
  • var destination = form.find('select[name="destination"] option:selected').val(); This how the destination name called to the string, i to call the attribute value to a var – NaFi Oct 21 '18 at 09:57