0

Is there any way to add fields dynamically to multiple select dropdownlist. Here is what i have tried

$('.applicationNameSelectClass').multiselect({
         numberDisplayed: 1,
        enableFiltering: true
});

function addField(){
    var val =document.getElementById("addField").value;
    $('#selectList').append('<option>'+val+'</option>');
}

<body>
Dynamically Add DropDown Field...<BR><BR>
<input type="text" id="addField"/>

<input type="button" id="theButton" value="AddField!" onclick="addField();">
<select id="selectList" name="applicationNames" class="applicationNameSelectClass" multiple="multiple" style="width: 147px; " >
    <option><c:out value="Option-1"/></option>
    <option><c:out value="Option-2"/></option>
    <option><c:out value="Option-3"/></option>
    <option><c:out value="Option-4"/></option>
    </select>
</body>

enter image description here

0

1 Answer 1

1

Seems like the onclick bind is not working for you inside the input element: onclick="addField();" Not sure why, but might be the order you're loading your page. I suggest you to use this code for binding click event:

$('#theButton').click(function() {
    var val = document.getElementById("addField").value;
    $('#selectList').append('<option>'+val+'</option>');
});

Remember to put it inside an ondomready context, like this Fiddle

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @jmartins for helping me out but still its not working...i have updated question with screen shot
Why not? It is working on this Fiddle. The only difference is that I didn't put bootstrap on it
without applying bootstrap plugin it works, but once you apply bootstrap plugin to dropdown list it's not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.