How i can get the value of this multiple choose dropdown box? I cant figure out how i can get the values. Please help on this. Thanks!
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet"/>
</head>
<body>
<select data-placeholder="Begin typing a name to filter..." multiple class="chosen-select" name="test" id="test">
<option value=""></option>
<option>American Black Bear</option>
<option>Asiatic Black Bear</option>
<option>Brown Bear</option>
<option>Giant Panda</option>
<option>Sloth Bear</option>
<option>Sun Bear</option>
<option>Polar Bear</option>
<option>Spectacled Bear</option>
</select>
<input type="text" name="getvalue" id="getvalue">
<input type="button" onclick="a()" value="Submit">
<script>
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found!"
});
function a() {
var value = document.getElementById('test').value;
document.getElementById('getvalue').value = value;
}
</script>
try this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet"/>
</head>
<body>
<select data-placeholder="Begin typing a name to filter..." multiple class="chosen-select" name="test" id="test">
<option value=""></option>
<option>American Black Bear</option>
<option>Asiatic Black Bear</option>
<option>Brown Bear</option>
<option>Giant Panda</option>
<option>Sloth Bear</option>
<option>Sun Bear</option>
<option>Polar Bear</option>
<option>Spectacled Bear</option>
</select>
<input type="text" name="getvalue" id="getvalue">
<input type="button" onclick="a()" value="Submit">
<script>
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found!"
});
function a() {
var value = $('#test').val();
$('#getvalue').val(value);
}
</script>
JsFiddle Link
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found!"
});
$("button").click(function() {
a = $(".chosen-select").val();
console.log(a);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://combinatronics.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://combinatronics.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet" />
<body>
<select data-placeholder="Begin typing a name to filter..." multiple class="chosen-select" name="test" id="test">
<option value=""></option>
<option>American Black Bear</option>
<option>Asiatic Black Bear</option>
<option>Brown Bear</option>
<option>Giant Panda</option>
<option>Sloth Bear</option>
<option>Sun Bear</option>
<option>Polar Bear</option>
<option>Spectacled Bear</option>
</select>
<input type="text" name="getvalue" id="getvalue">
<input type="button" onclick="a()" value="Submit">
<button>
click me
</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With