Browse By

How to get value and text from select control?

Spread the love

HTML Code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<select id="selectme">
<option value="1">text1</option>
<option value="2">text2</option>
<option value="3">text3</option>
</select>

Jquery Code for getting value from control

This is for getting text from the above given select control
<script>
$(document).ready(function(){
  $("#selectme").change(function(){    
	var test = $( this ).val();
	alert(test);
  });
});
</script>

Jquery Code for getting text from control

This is for getting value from the above given select control
<script>
$(document).ready(function(){
  $("#selectme").change(function(){    
	var test = $( "#selectme option:selected" ).text();
	alert(test);
  });
});
</script>

Output

jq

One thought on “How to get value and text from select control?”

Leave a Reply

Your email address will not be published. Required fields are marked *