Select / Dropdown - Are you sure confirmation confirmation

Select / Dropdown - Are you sure confirmation confirmation


I was wondering if someone could help me with this code, I have tried all kinds of things, but can not get the result I want.

As part of my internal application I have a select / dropdown list.  Which looks something like this.

  1. <select  class='bActions'>
  2. <option>ACTIONS</option>
  3. <option value='http://mydomain/edit_page'>edit</option>
  4. <option value='http://mydomain/delete_page' class='confirm_delete'>delete</option>
  5. </select>

Also I have 

  1.  $('.bActions').change(function() { window.location = $(this).val(); });
Which will load the page set in the value of the option.

Also I have:-

  1. $('.confirm_delete').click( function() { 
  2. if(confirm('Are you sure?')) { 
  3. data_url = $(this).attr('value'); 
  4. $.ajax({ type: "POST", url: data_url, success: function(txt) { 
  5. window.location.reload(); 
  6. });
  7.      } 
  8.   return false; 
  9.  });  
Which will popup a confirm box if the option has class confim_delete.  This also works. 

What I am having trouble with getting the two bits of code to work with each other.  I have tried nesting the code inside each other and other kinds of things, but I can not get the required result. 

Can someone please show me how I can.  

Have a select list so that when you click on option the page is loaded, unless the option has the class .confirm_delete, then a confim box pops to check if you really are sure.

Thanks




    • Topic Participants

    • mj