...

View Full Version : Pulling a JavaScript Variable To Send To PHP File



Dean440
02-03-2010, 05:33 PM
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?

Fumigator
02-03-2010, 05:42 PM
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.

Dean440
02-03-2010, 05:51 PM
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.:cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum