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.
- <ul data-role="listview" data-inset="true">
- <li data-role="list-divider">
- <div class="avatar">
- <img src="http://localhost/siteavatars/Actors/Bruce_Willis.jpg" alt="" />
- </div>
- <h4>title for first post in topic</h4>
- <p>by <a class="postedby" href="http://localhost/siteindex.php?action=profile;u=1">Itchme</a> -- July 10, 2012, 04:18:35 pm</p>
- <span style="position: absolute; right: 10px; top: 10px">
- <select id="post_options" name="post_options" class="post_options" data-icon="gear" data-iconpos="notext" data-select-menu="true" data-native-menu="false">
- <option>Post Options</option>
- <option value="http://localhost/siteindex.php?action=post;topic=3.0;num_replies=1">Reply</option>
- <option value="http://localhost/siteindex.php?action=post;msg=4;topic=3.0">Modify</a></option>
- <option value="http://localhost/siteindex.php?action=deletemsg;topic=3.0;msg=4;fcf524d3=66cb49192a102ee7ea35de6534b10ab4">Remove</option>
- <option value="http://localhost/siteindex.php?action=reporttm;topic=3.0;msg=4">Report to moderator</option>
- </select>
- </span>
- </li>
- <li><div class="message_body">Body of first post in topic</div></li>
- <a id="msg5"></a>
- <li data-role="list-divider">
- <div class="avatar">
- <img src="http://localhost/siteavatars/Actors/Bruce_Willis.jpg" alt="" />
- </div>
- <h4>title for second post in topic</h4>
- <p>by <a class="postedby" href="http://localhost/siteindex.php?action=profile;u=1">Itchme</a> -- July 10, 2012, 04:19:32 pm</p>
- <span style="position: absolute; right: 10px; top: 10px">
- <select id="post_options" name="post_options" class="post_options" data-icon="gear" data-iconpos="notext" data-select-menu="true" data-native-menu="false">
- <option>Post Options</option>
- <option value="http://localhost/siteindex.php?action=post;topic=3.0;num_replies=1">Reply</option>
- <option value="http://localhost/siteindex.php?action=post;msg=5;topic=3.0">Modify</a></option>
- <option value="http://localhost/siteindex.php?action=deletemsg;topic=3.0;msg=5;fcf524d3=66cb49192a102ee7ea35de6534b10ab4">Remove</option>
- <option value="http://localhost/siteindex.php?action=reporttm;topic=3.1;msg=5">Report to moderator</option>
- </select>
- </span>
- </li>
- <li><div class="message_body">Body message of second post.</div></li>
- </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.
- <script>
- $(document).ready(function() {
- $("#post_options").onclick(function(){
- var text = the text of the selected option. (remove, modify, reply, report);
- var url = the url that is set in the value="" attribute of the select option tag.
- });
- if(text == "Remove") {
- if(confirm("Remove this message?")) {
- if (url) {
- window.location = url;
- }
- }
- return false;
- }
- else {
- if (url) {
- window.location = url;
- }
- return false;
- }
- });
- </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