开发者

ComboBox "New Option" Option w/ Popup Input to add option

开发者 https://www.devze.com 2023-01-15 19:42 出处:网络
I\'m learning so be nice. I\'m developing a web app for a product management system.My office purchase wholesale from multiple vendors and direct.

I'm learning so be nice.

I'm developing a web app for a product management system. My office purchase wholesale from multiple vendors and direct.

My web app needs to accommodated basic "new vendor" creation within a product insert/update form.

Is there a simple way to have an option in my combo box "New Vendor" that opens an input box for entering the name, adding it to the list? I will have additional areas 开发者_开发百科to edit the vendor info, but I need to allow for quick-add within my form.

Suggestions? Directions? Comments? "Any help is good help, unless it's not help."

Thanks

-jt


So, I did some more research and I was just wording my question wrong. Here's what I got to work:

Script

<script type="text/javascript">
<!--
function message(value){
    if(value=="newVendor"){// New Vendor is selected
        var vendor = prompt("Vandor's Name","");

        var elementSelect = document.getElementById('vendor');

        try{
        elementSelect.add(new Option(vendor, vendor), elementSelect.options[2])
        }
        catch(ex){
        elementSelect.add(new Option(vendor, vendor), 2)
        }
    }
}
//-->
</script>

HTML

<div>
    <form>
        <select id="vendor" name="vendor" onChange="message(this.value);">
            <option value="scp">SCP</option>
            <option value="keller">Keller</option>
            <option value="newVendor">New Vendor</option>
        </select>
    </form>
</div>

Any comments would be helpful.

-jt

0

精彩评论

暂无评论...
验证码 换一张
取 消