Hi TenZor,
I've only just noticed SpanKie's reply but I'd nearly finished myself so you can have this too ... it's a slightly different way, but the crucial point was made by SpanKie.
Yes, your problem is that you can't 'call' PHP from the browser.
PHP only is working on the server ... it 'delivers' a page to the browser, but can't affect the page afterwards.
By contrast, javascript (which would go in the 'onClick') works at the client-side, i.e. the browser and that has no access at all to the server! So you can't 'call' PHP with javascript.
What you have to do is:
1) Submit the form along with the choice back to the SAME page
2) Set the session variable at the server
3) Re-display the form
Here's a template ...
<?php
// Every time the page is called, we check for a 'domain change'
// which only occurs when a user clicks the submit button on the
// form below, in which case $_GET['Select_Domain'] is 'set' (see the comment below).
if(isset($_GET['Select_Domain'])){
$_SESSION['CurrentDomain'] = $_GET['Domain_Choice'];
}
?>
<html><head><title>Form</title></head>
<body>
<?php
// Either display the current domain or a message
if(isset($_SESSION['CurrentDomain']){
echo '<h1>Current domain: '.$_SESSION['CurrentDomain'].'</h1>';
} else {
echo '<h1>Select a domain</h1>';
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>">
<select name="Domain_Choice">
<?php
foreach($_SESSION['DomainList'] as $DomainName){
echo '<option value="'.$DomainName.'">'.$DomainName.'</option>';
}
?>
</select>
<!-- Must submit the 'select' value back to the page'
along with the name of the submit button 'Select_Domain'
which will be accessible as $_GET['Select_Domain'] (see the note above) -->
<input type="submit" value="Select_Domain">
</form>
</body>
</html>