Question

This is my first question on this site, so I'm going to try to be as specific as i can... By the way, excuse me for my perfect knowledge of English... which isn't perfect at all..

So what I was wondering is: do php variables persist if you change your page's content, using AJAX methods?

Let me explain: I want to code a web app which has to contain a main layer, containing a few tabs. The user has to be able to write stuff into text areas in one tab, switch the tab, and if he wants so, come back to the first tab to complete what he wrote before (also the app has to keep the php variables that it created previously right?). The app also has to put all the data, entered in all the different tabs, in one or many databases, when a summit button is clicked; so it has to access all the variables created before.

I just don't have any code at this moment, but I want to do a specification file before starting to code, because what I am about to do is kinda massive app, so i hope you will be able to explain me this point.

I still thank you for your help.

Was it helpful?

Solution

You would be best to consider the PHP script as a one-off thing. It does what it is asked to, then terminates. Nothing is preserved.

However, if you NEED to preserve something to pass back with an AJAX call, you can do it by including:

<INPUT type='hidden' id='my_variable' value='my_value'>

This can be referenced by the javascript that calls your AJAX PHP page and thus be passed back.

For what you require, as @AlexP said, you can simply change the visibility of each tab content area with:

<SPAN onclick='toggle(this.id)' id='tab_1'>Tab Name</SPAN>

or similar. Your JS function might include something like:

for(n=1;n<=numberOfTabs;n++)
{
document.getElementById("div_"+n).style.display="none";
}
document.getElementById("div_"+passedid).style.display="block";

though there are other ways of doing it.

Perhaps what you REALLY want to do is save the entered data into a database field frequently (or even continuously).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top