简体   繁体   中英

Trigger function on chosen-select multiple

I need to increase or decrease the cost on selecting multiple options from a jquery multiple chosen select. The cost will increase on selecting options and will decrease by removing the option.

<select multiple="" class="chosen-select" id="form-field-select-4" data-placeholder="Choose a Department...">
    <option value="Management">Senior Management</option>
    <option value="Legal">Legal</option>
    <option value="Operations">Operations</option>
    <option value="Administration">Administration</option>
    <option value="R&D">R&D</option>
</select>

The cost will increase if end user chooses more departments and will decrease by removing the chosen department.

How can I trigger a function on change of this multiple select and how do I get if end user has added a new option or removed a chosen one?

You can use option:selected to get the selected options and use them to calculate the amount on change of selection of select. The will automatically remove the deselected options being returned by collection and you do not have to remember what is deselected and selected.

$("#form-field-select-4 option:selected")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM