JSFiddle - React, Tailwind, and code Playground

by Michael Prosser

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<select name="sample1">
  <option value="">Select</option>
  <option value="Apple" data-price="0.99">Apple</option>
  <option value="Orange" data-price="1.99">Orange</option>
</select>
<span class="your-selection"></span>

JavaScript

$('select[name="sample1"]').change(function(){

	if($(this).val()){
  
  	$('span.your-selection').text('The value is ' + $(this).val() + ' and the price is $' + $(this).find('option:selected').attr('data-price'));
  
  }

});