javascript - How to change select option with jquery? -
so have table class "vuln-table" , first column full of checkboxes, while last column options
i've figured out how alert box rows contain checked checkbox; however, need figure out how change value of selected option
here's js file:
function change_severity(severity) { $(".vuln-table tr").each(function() { $(this).find('td input:checked').each(function() { // row has checkbox selected // row needs have select value changed }); }); }
here's html contains options
<tr role="row" class="even"> <td class="sorting_1"><input type="checkbox" name="asfasdfd" id="vuln_checked_" value="asdfsdfa"></td> <td>something</td> <td><select class="form-control" name="test" id="kjhtkjehtehr"><option value="severe">severe</option> <option value="high">high</option> <option value="medium">medium</option> <option selected="selected" value="low">low</option> <option value="informational">informational</option> </select> </td> <td></td> </tr>
i'm passing in severity through button click, , equals 1 of values. want have selected option change whatever "severity" set to. if pass "severe" function, selected option should "severe".
http://jsfiddle.net/v1pje44v/12/
the below function fix issue
function change_severity(severity) { $(".vuln-table tr").each(function() { $(this).find('td input:checked').each(function() { $(this).parent().parent().find("select").val(severity); }); }); }
Comments
Post a Comment