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');     }   }); });​ 

you can give try here.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -