acctman Posted July 7, 2009 Share Posted July 7, 2009 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> Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/ Share on other sites More sharing options...
MadTechie Posted July 7, 2009 Share Posted July 7, 2009 yes Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870384 Share on other sites More sharing options...
acctman Posted July 7, 2009 Author Share Posted July 7, 2009 yes can you provide an example? Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870404 Share on other sites More sharing options...
MadTechie Posted July 7, 2009 Share Posted July 7, 2009 see any Ajax example, or use cookies Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870413 Share on other sites More sharing options...
acctman Posted July 7, 2009 Author Share Posted July 7, 2009 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. Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870420 Share on other sites More sharing options...
MadTechie Posted July 7, 2009 Share Posted July 7, 2009 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! Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870452 Share on other sites More sharing options...
acctman Posted July 7, 2009 Author Share Posted July 7, 2009 thanks... that help out a lot. Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870521 Share on other sites More sharing options...
MadTechie Posted July 7, 2009 Share Posted July 7, 2009 Your welcome..! Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-870555 Share on other sites More sharing options...
bogdA Posted June 9, 2012 Share Posted June 9, 2012 i used the abve script, works on IE9/Chrome 19 with a small issue: sometimes i have to do a manual reload to display the selected value, but on Firefox ... nothing happens. can you help me? thk Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-1352423 Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2012 Share Posted June 9, 2012 Perhaps you didn't notice, but this thread is nearly 3 years old. Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-1352428 Share on other sites More sharing options...
bogdA Posted June 9, 2012 Share Posted June 9, 2012 i did, and i also saw the message about posting a new thread, but i thought there is no problem in posting in the original thread and still someone could help me thk Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-1352439 Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2012 Share Posted June 9, 2012 You'd be better off posting a new thread. Especially since this one is already marked as "solved". Link to comment https://forums.phpfreaks.com/topic/165057-solved-onselect-or-onchange-code-help-needed/#findComment-1352446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.