javascript - How to get the value of dropdown and display in label -
i have dropdown filling content dynamic data , in model appending data dropdown
$("#dpp").append($("<option disabled></option>").val(0).html('select locations')); $("#dpp").append($("<option selected='selected'></option>").val(1111).html('all')); (var = 0; < location.length; i++) { $("#dpp").append($("<option></option>").val(data[i].sno).html(data[i].name)); }
i unable value , text of selected option using change handler.
i tried:
$('#dpp').change(function () { var thisvalue = $(this + "option:selected").text(); alert(thisvalue); });
and default on page load all option selected in dropdown.
how can value or text , show on label?
for change event , document ready:
$(document).ready(function() { getselectdata($('#dpp')); }); $('#dpp').on('change', function() { getselectdata($(this)); }); function getselectdata(el) { var $option = el.find('option:selected'); var text = $option.text(); var val = $option.val(); alert('option text: ' + text + '; option value ' + val) }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="name" id="dpp"> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
Comments
Post a Comment