SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript + PHP

    Hey guys, I'm working on a small project for myself and I want to be able to add new folders using JavaScript. You click the add button, a pop-up message comes up with a form box asking the name of the folder, type the name, and then when you press okay it will add the folder. How can I take there input value, and use it in PHP? Here is my baby script so far.


    HTML Code:
    <html>
    <script type="text/javascript">
    <!--
    
            function addfolder()
            {
                    var folder_name = prompt("please enter the folder name")
    
                    alert(folder_name);
            }
    
            
            
    //-->
    </script>
    <body>
    <form method="POST">
              <p>
              <a href="#" onclick="addfolder()">Add New</a>
              </p>
    </form>
    </body>
    </html>
    
    <?php
    if ($_POST['do'] == 'doaddfolder')
    {
    	//echo $_POST['folder_name'];
    }
    ?>
    Thanks!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,227
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    Post javascript prompt value to PHP

    You could use a hidden input and give it the value from the prompt. Maybe something like:
    HTML Code:
    <input type="hidden" id="prompt_val" name="prompt_val" val="" />
    Code:
    function addfolder()
            {
                    var folder_name = prompt("please enter the folder name")
                    var hidden_input = document.getElementById('prompt_val');
                    hidden_input.value = folder_name;
                    alert(folder_name);/*submit() form here instead?*/
            }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •