php - Dynamically select fields from a list and add them to a form -


in form need dynamically add (and remove) fields (0 n) select.

every item should removed list after being added can't selected twice.

for example have select this:

 <select name="list">     <option value="1">a</option>     <option value="2">b</option>     <option value="3">c</option>     <option value="4">d</option>   </select> 

and want add new field in form shows , d , stores values can through post. if click on select, there b , c.

can me?

what type of fields want? input type text? if so:

$("[name=list]").on("change", function (e) {     var val = $(this).val();     if (val.length > 0) {         $(this).find("option:selected").remove();         $("<input>").attr("name", "the-name").val(val).appendto($("#the-form"))     } }); 

check out fiddle https://jsfiddle.net/etoysp7b/1/


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -