javascript - Select-box control with jquery -
i using selectbox:
<select name="priority" id="priority">     <option value="4">low</option>     <option value="3" selected="selected">normal</option>     <option value="2">high</option>     <option value="1">emergency</option> </select>   when user select "emergency", confirmation box opens , if user confirm, "emergency" selected. otherwise "normal" should selected. this, using jquery:
$(document).ready(function() {     $('#priority').change(function(){         if($(this).val()=='1'){             if(confirm("are sure emergency?")){                 return true;             }             else{                 //here code needed select "normal".             }         }     }); });   now, how can that?
since you're returning in confirmation case, can shorten logic down this:
$(function() {   $('#priority').change(function(){     if($(this).val()=='1' && !confirm("are sure emergency?")){       $(this).val('3');     }   }); });        
Comments
Post a Comment