How to get selected text of dropdown in jquery
Dropdowns are always doing a great job in web development, So there selected values are very important for doing task. you can <strong>get selected text of dropdown in jquery</strong> by this simple code.
by Dinocanid
HTML
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<label>
<input type="radio" name="test" value="small">
<img src="http://placehold.it/40x60/0bf/fff&text=A">
A
</label>
<label>
<input type="radio" name="test" value="big">
<img src="http://placehold.it/40x60/b0f/fff&text=B">
B
</label>
<label>
<input id="up_radio" type="radio" name="test" value="update">
<img src="http://placehold.it/40x60/b0f/fff&text=C">
</label>
CSS
/* HIDE RADIO */
[type=radio] {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
/* IMAGE STYLES */
[type=radio] + img {
cursor: pointer;
}
/* CHECKED STYLES */
[type=radio]:checked + img {
outline: 2px solid #f00;
}
JavaScript
$(document).ready(function(){
$('#mydropdown').change(function(){
$selected_value=$('#mydropdown option:selected').text();
$('#result').text($selected_value);
});
});
$('input[name="test"]').on('change', function(){
if ($(this).val()=='update') {
//change to "show update"
$("#result").text("show update");
} else {
$("#result").text("show Overwritten");
}
});