title: Click on Anchor Tag in Modal box send href link to AJAX
body: <p>Respected Community,</p>
  
  <p>I'm working on a task which requires that when a user clicks on upload button of a Dropzone box, a Modal Box must appear asking the user where to save the uploading files on localhost. The Modal Box shows a list of already existing directories in a certain drive and provides an option to create a new Folder if desired. Clicking on Create a new Folder button from Modal Box 1 opens up another Modal Box which asks the user to input Foldername which is sent through AJAX to a php page that creates user defined folder in the directory.</p>
  
  <p>The problem I'm facing is that, upon clicking the foldername from already existing folders list in Modal Box 1, the selected foldername must be sent through AJAX to another php page from where the dropzone can know where to upload the files. Any help will be highly regarded.</p>
  
  <p>Thanks...</p>
  
  <p><strong>Here is my code that takes foldername from the user and creates a Folder in a directory:</strong></p>
  
  <pre><code>$foldername = $_REQUEST['foldername'];
  $structure = dirname(__FILE__) . DIRECTORY_SEPARATOR . $foldername;
  if(!file_exists($structure)){
    if(mkdir($structure, 0777, true)) {
      die('Success');
    }else {
      die("Folder `{$structure}` failed to be created");
    }
  }
  </code></pre>
  
  <p><strong>Here's the code to upload dropzone files in user defined folder (which is not currently working):</strong></p>
  
  <pre><code>$ds = DIRECTORY_SEPARATOR;
  $storeFolder = 'uploads/'; // "$_POST['variable']" is the folder where files will be uploaded  
  if (!empty($_FILES)) {
      $tempFile = $_FILES['file']['tmp_name'];          
      $targetPath = dirname( __FILE__ ) . $ds . $storeFolder . $ds;         
      $targetFile =  $targetPath . $_FILES['file']['name'];     
      move_uploaded_file($tempFile, $targetFile);         
  }
  </code></pre>
  
  <p><strong>Here is the JavaScript code that I'm using to perform tasks:</strong></p>
  
  <pre><code>$( function() {
  var dialog, dialogMain, form;
  var name = $("input[name=name]");
  var path = $("input[name=path]");
  var allFields = $( [] ).add( name ).add( path );
  
  function addFolder() {
    var valid = true;
    allFields.removeClass( "ui-state-error" );
    if (valid) {
      $( "#users tbody" ).append( "&lt;tr&gt;" +
        "&lt;td&gt;" + "&lt;a href='#'&gt;" + name.val() + "&lt;/a&gt;" + "&lt;/td&gt;" +
        "&lt;td&gt;" + path.val() + "&lt;/td&gt;" +
      "&lt;/tr&gt;" );
      dialog.dialog( "close" );
    }
    return valid;
  }
  
  dialog = $( "#dialog-form" ).dialog( {
    autoOpen: false,
    height: 350,
    width: 350,
    modal: true,
    buttons: {
      "Create a Folder" : {
          text: "Create a Folder",
          id: "indlg",
          click: addFolder 
      },
      Cancel: function() {
        dialog.dialog( "close" );
      }
    },
    close: function() {
      form[ 0 ].reset();
      allFields.removeClass( "ui-state-error" );
    }
  });
  
  dialogMain = $( "#main-dialog" ).dialog( {
    autoOpen: false,
    height: 300,
    width: 390,
    modal: true,
    buttons: {
      Cancel: function() {
          dialogMain.dialog( "close" );
      }
    }
  });
  
  form = dialog.find( "form" ).on( "submit", function( event ) {
    event.preventDefault();
    addFolder();
  });
  
  $( "#createFolder" ).button().on( "click", function() {
    dialog.dialog( "open" );
  });
  
  $( "#upload" ).button().on( "click", function() {
    dialogMain.dialog( "open" );
  });
  
  $('#indlg').click(function() {
      $.ajax({
        url: 'create.php',
        type: 'POST',
        data: { foldername : name.val() },
        success: function(output) {
          alert(output);
        }
      });
  });
  </code></pre>
  
  <p>} );</p>