Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sessions and refresh page

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hey,

I have 2 buttons on my page. When I hit the first button my session gets the value '1' and refreshes the page, when I hit the second button my session gets the value '2' and refreshes the page. How can I make this work? I thought of something like this but it doesn't work.

<input type=&quot;button&quot; value=&quot;1&quot; name=&quot;toevoegen&quot; onClick=&quot;1();&quot;>
<input type=&quot;button&quot; value=&quot;2&quot; name=&quot;toevoegen&quot; onClick=&quot;2();&quot;>

<script language=&quot;JavaScript&quot;>
function 1()
{
<? $_SESSION['action'] = 1; ?>
location.reload()
}

function 2()
{
<? $_SESSION['action'] = 2; ?>
location.reload()
}
</script>


One way or the other the session gets always the value 2.
Can someone help me please? The One And Only KryptoS
 
That's correct behavior. $_SESSION is only getting set when the script is run on the server. The last statement PHP runs is the one which sets the variable to 2.

You're confusing server-side scripting through PHP with client-side scripting through JavaScript. The two are separate.

If you want session variables to be updated according to input, your page must submit data to a script on your server. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top