I have a list like this :
<p>Please select :</p>
<script type="text/javascript"></script>
<select id='pre-selected-options1' multiple='multiple'>
<option value='elem_1' selected>1</option>
<option value='elem_2'>2</option>
<option value='elem_3'>nextoption</option>
<option value='elem_4' selected>option 1</option>
<option value='elem_100'>option 2</option>
</select>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="js/jquery.multi-select.js"></script>
<script type="text/javascript">
$('#pre-selected-options1').multiSelect();
</script>
</div>
i have a text box and i need to add the text box values into this list. For time being i need it like whenever the page reloads everything entered is reset. Later on i will connect to db.
<label>Enter: </label>
<input type="text" name="" class="input-default"><button type="button" class="btn btn-success btn-sm m-b-10 m-l-5">Add</button>
How to add the value entered in text box to this list on button click?
demo
Python list can contain duplicate elements.
Using each() check value of inputs and if any value is duplicate add class duplicate to it.
A text box is an object you can add to your document that lets you put and type text anywhere in your file. Text boxes can be useful for drawing attention to specific text and can also be helpful when you need to move text around in your document.
<select id='pre-selected-options1' multiple='multiple'>
<option value='elem_1' selected>1</option>
<option value='elem_2'>2</option>
<option value='elem_3'>nextoption</option>
<option value='elem_4' selected>option 1</option>
<option value='elem_100'>option 2</option>
</select>
<!-- This is the list (above)-->
<br>
<label>Enter: </label>
<input type="text" name="" id="inp" class="input-default">
<button type="button" onclick="add()" class="btn btn-success btn-sm m-b-10 m-l-5">Add</button>
<!-- This is the textbox-->
<script>
function add()
{
var x = document.getElementById("pre-selected-options1");
var option = document.createElement("option");
option.text = document.getElementById("inp").value;
x.add(option);
}
</script>
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