Is there any HTML/JavaScript code that can allow the viewer of a webpage to add a option to a dropdown select list by typing it in a text box???
Very basic example. No CSS, fancy formatting, error checking, anything. The value of the new option will be identical to the displayed string.
function newOpt() {
var $inp = $('#newOptIpt');
var v = $inp.val();
$('#modSelect').append('<option value="' + v + '">' + v + '</option>');
$inp.val('')
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<select id="modSelect">
<option value="default-1">Default option</option>
</select>
<br><br>
<input id="newOptIpt"/>
<button onclick="newOpt();">Add Option</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