Jump to content

Recommended Posts

I'd for the user to select a folder from the select box and immediately have the value stored in a session id so it can be recalled else where. I'd like for this to be done dynamically with an OnSelect or OnChange so the user does not have to click a submit button or anything like that. Is that possible?

 

 

<select name="folder">
<option value="" selected="selected">Select</option>
<option value="1">Public</option>
<option value="2">Mobile</option>
<option value="3">Private</option>
</select>

 

 

can anyone else assist me with more help, something less general. I understand that ajax and java can be used that's why I came to this section to ask for help. I do know that OnSelect or maybe OnChange can be used I just do not know how to write the code or what to search for.

Your question is too general,

 

here's some code (basic ajax) but I added an option to view the set session as it seams pointless to set it an do nothing with it!

<?php
session_start();
if(!empty($_GET['session']))
{
$_SESSION['session'] = $_GET['session'];
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Set session</title>
</head>
<body>
<script language="javascript">
function ajaxFunction(session)
{
   var loaderphp = "<?php echo $_SERVER['PHP_SELF'] ?>";
   var xmlHttp;
   try
    {
      xmlHttp=new XMLHttpRequest();
    }catch(e){
      try
      {
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }catch(e){
         try
         {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }catch(e){
            alert("Your browser does not support AJAX!");
            return false;
         }
      }
   }
    xmlHttp.open("GET", loaderphp+"?session="+session,true);
    xmlHttp.send(null);
}
</script>
<form action="" method="post" enctype="multipart/form-data">
<select name="folder" onchange="javascript:ajaxFunction(this.value);">
<option value="" selected="selected">Select</option>
<option value="1">Public</option>
<option value="2">Mobile</option>
<option value="3">Private</option>
</select>
</form>
<a href="?show=true">Show set session</a>
<?php
if(!empty($_GET['show'])) echo "Your session is set to {$_SESSION['session']}";
?>
</body>
</html>

 

Using a cookie would work just as well and won't need to make a server call, and would be very short and simple code but without more detail I can't make any real suggestions!

  • 2 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.