1

Prefer this example so you have better idea for give answer

<select id="cmbfotos" onchange="aplicarFoto()"> <option value="gokussj3.jpg">Value 1</option> <option value="gokussj4.jpg">Value 2</option> <option value="gohanssj2.jpg">Value 3</option> <option value="gotenks.jpg">Value 4</option> <option value="krilin.jpg">Value 5</option> </select> 

In above ex. when i select two value like Value1 and value2 both value i require so how to i get it.

i not require value like "gokussj3.jpg" but Value 1

If some idea share me .....

1
  • What do you mean "two value", it's not a multiple, so you can only select one value ? Commented Apr 26, 2014 at 11:10

4 Answers 4

2

Access the options, filtering by :selected, then get the .text().

Fiddle

$('#cmbfotos option:selected').text(); 
Sign up to request clarification or add additional context in comments.

Comments

1

Use this solution for your requirement

// Use for multiple select in select

 $('#cmbfotos option').each(function() { if($(this).val() == 'gokussj3.jpg') { $(this).prop("selected", true); } }); 

// Get the value from a drop down select

$( "#cmbfotos option:selected").val(); 

// Get the value from a dropdown select even easier

$( "select.foo" ).val(); 

// Get the value from a checked check box

$( "input:checkbox:checked" ).val(); 

// Get the value from a set of radio buttons

$( "input:radio[name=bar]:checked" ).val(); 

Comments

1

You should use jquery .change() for select onchange event, :selected to select all elements that are selected and .text() to get text from element. Try this:

$("#cmbfotos").change(function(){ var text = $(this).find("option:selected").text(); alert(text); }); 

DEMO

Comments

1
$('#cmbfotos option:selected').text(); ////is for text and $('#cmbfotos option:selected').val() ///is for value; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.