Menu for uploading from a web URL or from ones computer
I am trying to reproduce on my homemade site a feature that I have seen on many forums, namely
a pop-up menu that allows the user to upload a file either from a URL or from the user's computer.
(thus, what I am looking for is exactly like what happens when the portrait icon is clicked at
http://math.stackexchange.com/questions/ask for example).
The nearest I could reach so far is the very incorrect and very ineffective code below. Any help appreciated.
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>jQuery UI Dialog functionality</title>
- <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
- <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
- <!-- CSS -->
- <style>
- .ui-widget-header,.ui-state-default, ui-button{
- background:#b9cd6d;
- border: 1px solid #b9cd6d;
- color: #FFFFFF;
- font-weight: bold;
- }
- </style>
- <!-- Javascript -->
- <script>
- $(function() {
- $( "#mydialog" ).dialog({
- autoOpen: false,
- modal: true,
- buttons: {
- "_File": function() {
- $( this ).dialog( "close" );
- },
- "_Web": function() {
- $( this ).dialog( "close" );
- },
- },
- title: "Upload File",
- position: {
- my: "left center",
- at: "left center"
- }
- });
- $( "#myopener" ).click(function() {
- $( "#mydialog" ).dialog( "open" );
- });
-
- $('#uploadWeb').hide();
- $('#uploadFile').hide();
-
- // apply onclick handler to radio buttons
- $('#upload_file_button').click(function() {
- $('#uploadWeb').show();
-
- }
- $('#upload_web_button').click(function() {
- $('#uploadFile').show();
-
- }
- });
- });
- </script>
- </head>
- <body>
- <!-- HTML -->
- <div id="mydialog" title="Dialog Title goes here...">
- This my first jQuery UI Dialog!</div>
- <button id="myopener">Open Dialog</button>
-
- <form method="post">
- <div id="uploadType">
- <input type="radio" name="upload_file_button" value="file" /> Computer<br />
- <input type="radio" name="upload_web_button" value="web" /> Web<br />
- </div>
- <div id="uploadFile">
- <input type="file" name="upload_file" />
- </div>
-
- <div id="uploadWeb">
- <input type="text" name="upload_web" placeholder="Enter URL to file" />
- </div>
-
- </form>
- </body>
- </html>