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.
- <select class='bActions'>
- <option>ACTIONS</option>
- <option value='http://mydomain/edit_page'>edit</option>
- <option value='http://mydomain/delete_page' class='confirm_delete'>delete</option>
- </select>
Also I have
- $('.bActions').change(function() { window.location = $(this).val(); });
Which will load the page set in the value of the option.
Also I have:-
- $('.confirm_delete').click( function() {
- if(confirm('Are you sure?')) {
- data_url = $(this).attr('value');
- $.ajax({ type: "POST", url: data_url, success: function(txt) {
- window.location.reload();
- }
- });
- }
- return false;
- });
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