Onclick select menu url redirect

Onclick select menu url redirect

In my mobile theme that I'm working on, I have a list of replies to an article. Next to each reply is a button that one can click (or touch) to view a select menu for options to reply, report, remove etc. assuming they have permissions. My problem is for the option to remove I want a JavaScript confirm() to give the user the option to proceed so that there isn't anyone getting mad for accidentally removing a reply. :) I cannot figure out how to get the value(the url) of the selected option. Here's the source code of the page that I'm working on.

  1. <ul data-role="listview" data-inset="true">
  2. <li data-role="list-divider">
  3. <div class="avatar">
  4. <img src="http://localhost/siteavatars/Actors/Bruce_Willis.jpg" alt="" />
  5. </div>
  6. <h4>title for first post in topic</h4> 
  7. <p>by <a class="postedby" href="http://localhost/siteindex.php?action=profile;u=1">Itchme</a> -- July 10, 2012, 04:18:35 pm</p>
  8. <span style="position: absolute; right: 10px; top: 10px">
  9. <select id="post_options" name="post_options" class="post_options" data-icon="gear" data-iconpos="notext" data-select-menu="true" data-native-menu="false">
  10. <option>Post Options</option>
  11. <option value="http://localhost/siteindex.php?action=post;topic=3.0;num_replies=1">Reply</option>
  12. <option value="http://localhost/siteindex.php?action=post;msg=4;topic=3.0">Modify</a></option>
  13. <option value="http://localhost/siteindex.php?action=deletemsg;topic=3.0;msg=4;fcf524d3=66cb49192a102ee7ea35de6534b10ab4">Remove</option>
  14. <option value="http://localhost/siteindex.php?action=reporttm;topic=3.0;msg=4">Report to moderator</option>
  15. </select>
  16. </span>
  17. </li>
  18. <li><div class="message_body">Body of first post in topic</div></li>
  19. <a id="msg5"></a>
  20. <li data-role="list-divider">
  21. <div class="avatar">
  22. <img src="http://localhost/siteavatars/Actors/Bruce_Willis.jpg" alt="" />
  23. </div>
  24. <h4>title for second post in topic</h4> 
  25. <p>by <a class="postedby" href="http://localhost/siteindex.php?action=profile;u=1">Itchme</a> -- July 10, 2012, 04:19:32 pm</p>
  26. <span style="position: absolute; right: 10px; top: 10px">
  27. <select id="post_options" name="post_options" class="post_options" data-icon="gear" data-iconpos="notext" data-select-menu="true" data-native-menu="false">
  28. <option>Post Options</option>
  29. <option value="http://localhost/siteindex.php?action=post;topic=3.0;num_replies=1">Reply</option>
  30. <option value="http://localhost/siteindex.php?action=post;msg=5;topic=3.0">Modify</a></option>
  31. <option value="http://localhost/siteindex.php?action=deletemsg;topic=3.0;msg=5;fcf524d3=66cb49192a102ee7ea35de6534b10ab4">Remove</option>
  32. <option value="http://localhost/siteindex.php?action=reporttm;topic=3.1;msg=5">Report to moderator</option>
  33. </select>
  34. </span>
  35. </li>
  36. <li><div class="message_body">Body message of second post.</div></li>
  37. </ul>

What I want to do is to redirect them to the url of the value="" in the selected option. BUT, if the remove option is selected, I need a confirmation box to popup and ask them first. Here's some pseudo code to see what I'm saying.

  1. <script>
  2. $(document).ready(function() {
  3. $("#post_options").onclick(function(){
  4. var text = the text of the selected option. (remove, modify, reply, report);
  5. var url = the url that is set in the value="" attribute of the select option tag.
  6. });

  7. if(text == "Remove") {
  8. if(confirm("Remove this message?")) {
  9. if (url) {
  10. window.location = url;
  11. }
  12. return false;
  13. else {
  14. if (url) {
  15. window.location = url;
  16. }
  17. return false;
  18. }
  19. });
  20. </script>

The part I can't figure out is how to get both the text, and the URL from the select menu. Since jquerymobile completely changes things behind the scenes, I can't quite figure it out. Any help would be greatly appreciated.

Itchme