You need to understand the fundamentals of client-server programming, especially as it applies to a browser-based client.
*ANY* server-side code in your page (in your case, that means any PHP code) is execute LONG BEFORE the page is sent to the browser (well..."LONG" maybe be milliseconds, but that is forever for a computer).
That means that, in your code
Code:
function getShip() {
var shipId;
shipId = document.getElementById("sel_ship").value;
<?php $_SESSION['shipid']=$_GET['shipId'];?>
}
the PHP code set the SESSION value *BEFORE* the browser EVER SAW this page. It's already been done. Milliseconds or seconds or even minutes ago.
NOTHING AT ALL is happening in PHP when the <select> is changed!!!
*ONLY* when the ENTIRE <FORM> is sent back to the server will PHP get a chance to see the <select> value.
***************
Unless...
Unless you use AJAX (or AJAX-like coding) to send the data back to a *separate* PHP page as soon as the selection is made.
Yes, you *can* do that, but I question what the point of it is.
So you change the session value when the user changes the <select>. And then a moment later he changes his mind, chooses another <option>, and you have to send another AJAX request to change the session value.
But what's the point??? NO OTHER USER can see that session value. And the only time your PHP code is going to be able to use the session value (presumably) is on the next PHP page that the user asks for.
So why not just change the session value only when the <form> is submitted???