javascript - Get index or value of clicked option from multiple select -


I have more than one selection in which I want to click on the option on which I was cliked.

If I click on the first option then display the first option index or value .

HTML code

  & lt; Select class = "founder_designation" rel = "designation" placeholder = "designation" multi = "multiple" name = "designation" & gt; & Lt; Option value = "" & gt; - Choose a Designation - & lt; / Options & gt; & Lt; Option value = "president_management" director & gt; President & amp; Amp; Managing Director & lt; / Option & gt; & Lt; Option selected = "selected" value = "director" & gt; Director & lt; / Option & gt; & Lt; Option value = "whole_time director" & gt; Full-time Director & lt; / Options & gt; & Lt; Option value = "Other" & gt; Other & lt; / Options & gt; & Lt; / Select & gt;  

jQuery code

  $ ("founder_designation"). ("Change", function () {warning ($ (this) .val ()); // it displays all selected options separated by commas})  

< Strong>

This will do the trick,

  $ ('. Founder_designation'). ('Click', 'option', function () {warning ($ (this) .val ());});  

If you want all values ​​then try something like this,

  $ ('.finder_designation'). ('Click', 'option', function () {warning ("click value:" + $ (this) .val ()); $ a = $ ('founder_designation option: selected'); $ str = ' '; ($ I = 0; $ I  

Demo check


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -