I have a text input with a button. When I fill in the input and click the button I want to add that information to a select. Please can anyone one help, I can’t find an example anywhere.
Input & button
<input id="new_menu_name" type="text" name="new_menu_name" placeholder="Please enter your menu title">
<input class="add_menu_item" name="add_menu_item" value="Add" type="button">
Select
<select name="menu_items" id="menu_items" size="8" multiple="multiple" style="height:200px; width:250px;">
</select>
I have tried using this script but with no luck
$(document).ready(function() {
$(".add_menu_item").click(function(){
$('#menu_items').
append($("<option></option>").
attr("value").
text(value));
});
When you call
attr, you’re not actually setting a value: you’re retrieving the current value of thevalueattribute. You should use thevalfunction to set the value:Now that I’ve seen your full code, it’s clear that the other problem is that you aren’t setting the
valuevariable. I think you probably want something like this:(NB also that I’ve changed the fiddle to use jQuery rather than Mootools.)