Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts

    Pulling a JavaScript Variable To Send To PHP File

    This is a problem that I'm not sure how to solve.

    I have a file editor that can pull up the content section of every page on the server. You simply click a file name in one column, and using AJAX, that page is pulled up from the database and displayed in a textarea.

    There is a Javascript variable named "currentFile" that keeps track of the file we're currently working with. For example, it may contain the string "index.php". When you click another file, it changes.

    This is great for just pulling up pages into the textarea, but since I suck at AJAX, I'd rather have the save button just do things the old fashioned way and send the textarea contents via the POST method to a PHP script that will update the database.

    My question is, how do I access the currentFile variable in my Javascript from my HTML form, so that my PHP script knows which file to update?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can use a hidden form input element. Assign the value of your JS variable to this hidden element before submitting the form to your PHP script and it will then be available in the $_POST array.

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by Fumigator View Post
    You can use a hidden form input element. Assign the value of your JS variable to this hidden element before submitting the form to your PHP script and it will then be available in the $_POST array.
    Thank you Fumigator. I actually got it solved using that very method before I read your reply. I guess I should have thought it through a little more before I posted this thread.

    Thanks again.


  •  

    Posting Permissions

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