MannyG Posted April 29, 2010 Share Posted April 29, 2010 Hey, I have a dropdown menu which on-selection of something from it, sends that value to the URL while remianing on the same page, so is it possible to grab this value and store it into a database? I want to do this without form submital...so the $_GET, didn't really work for me...ideas? Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/ Share on other sites More sharing options...
otuatail Posted April 29, 2010 Share Posted April 29, 2010 No can't do that. I sugest a submit to a code only page and a re-direct back to the page Desmond. Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/#findComment-1050739 Share on other sites More sharing options...
teamatomic Posted April 29, 2010 Share Posted April 29, 2010 Not without the use of ajax. You'd be best to do as suggested above. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/#findComment-1050752 Share on other sites More sharing options...
MannyG Posted April 30, 2010 Author Share Posted April 30, 2010 Problem with submitting it is I have 3 drop-down menus appearing, and the last 2 appear if the one before them has a selected value. What I want to do is save ALL three of these values, but my code only saves the most recently clicked value...they are all in a form so once I have the values saved I want to put them into a hidden field so I can pass them through to the class...but I need to have all 3 values saved! Unfortunately it only saves one, the most recently selected....ideas..? Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/#findComment-1050821 Share on other sites More sharing options...
ChemicalBliss Posted April 30, 2010 Share Posted April 30, 2010 You mean like a country -> state -> city type form, You have 2 options: 1. Print out all the possible drop downs, hide all of them in divs, except for the default ones. Then use pure javascript functions to show and hide the divs depending on which country etc was selected. (Can be easy if you know javascript). 2. Use AJAX to submit the country selected to a script on the website, that script responds with the proper drop-down box and AJAX writes it to the page. This second method is much lighter on the bandwidth (depending on what exactly gets requested and sent between AJAX and the webserver). Both require Client Side Javascript Code to update the page without moving/refreshing. But there is a 3rd option, as suggested above you could use session variables to store the selected results, and refresh the page, or submit the page to itself and handle it accordingly. -cb- Note: I suggest AJAX - Get in there and muck about with it, its much simpler than you think. Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/#findComment-1050882 Share on other sites More sharing options...
teamatomic Posted April 30, 2010 Share Posted April 30, 2010 Here is a simple example to get you started. As you can see this one uses prototype. <html> <head> <title>Weather Widget></title> <script type="text/javascript" src="prototype.js"></script> <script> function sendRequest() { new Ajax.Request("parse.php", { method: 'post', postBody: 'state='+ $F('state'), onComplete: showResponse }); } function showResponse(req){ $('show').innerHTML= req.responseText; } function sendCityRequest() { new Ajax.Request("parse.php", { method: 'post', postBody: 'city='+ $F('city'), onComplete: showCityResponse }); } function showCityResponse(req){ $('show').innerHTML= req.responseText; } </script> </head> <body> <div style="width:750px;"> <form id="widget" onsubmit="return false;"> <?php include("./states_select.txt"); ?> </form> <div id="show" style="margin-top:0px;"></div> </div> The parse.php file would be the same as if you had manually submitted a form. The include"states_select.txt" file is a simple drop down of the US States. The div id=show is the div that prototype uses to display the results from the parse.php file. In the js the first function handles the request to the parse.php file for the city drop down from the selected state. The second function is the response from the parse.php file back to the page to display the city drop. The third function mimics the first except it is for the city drop down response from the parse.php file. The fourth function is for the response from the parse.php file to display the proper weather data for the selected city. As you can see by the js and the explanation you kinda work one step ahead of yourself and everything is a set of request/response. I suggest you use the example to get your first drop down displayed with the include then use the first request/response set to display your second drop down. From there it should be easy sailing. Note: what the browser displays in the "show" div will not be visible in the source. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/#findComment-1051028 Share on other sites More sharing options...
MannyG Posted April 30, 2010 Author Share Posted April 30, 2010 Thank you for that teamatomic...I have never used AJAX and my javascript is fairly low, so a lot of that flew over my head...however I have it working where it shows each dropdown after another is selected based on specific query, so that part work's fine..I used the $_SESSION array in order to capture and store the selected variables, however it seems that it will display only one or two variables and leave out one of the others, quite weird...I will post my code here... //grabs codeline from dropdown $getcodeline = $_GET['version']; $getbuild = $_GET['bundle']; $getdevice = $_GET['device']; echo "<center><h1><b>Add Info</b></h1></br></center>"; print "\t<form id='sort' method='GET'>\n"; //Codeline drop down menu $distinctcodeline = mysql_query("SELECT DISTINCT version FROM build"); echo "<select name='version' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">"; echo "<option>Select Codeline</option>"; while($search=mysql_fetch_array($distinctcodeline)){ echo"<option>".$search['version']."</option>"; echo "</br>"; } echo "</select>"; $random = $_SESSION['version']; $_SESSION['version'] = $getcodeline; echo $random; if (isset($getcodeline) && $getcodeline!=null){ //select bundle based on codeline selected... $specificBundle = mysql_query("SELECT DISTINCT bundle FROM build WHERE version = '$getcodeline'"); echo "<select name='bundle' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">"; echo "<option>Select Bundle</option>"; while($searching=mysql_fetch_array($specificBundle)){ echo"<option>".$searching['bundle']."</option>"; echo "</br>"; } echo "</select>"; $check = $_SESSION['bundle']; $_SESSION['bundle'] = $getbuild; echo $check; } if (isset($getbuild)){ //select device based on bundle selected... $selectBuild_id = mysql_query("SELECT DISTINCT build.build_id FROM build WHERE (build.bundle = '$getbuild')"); $build_id=mysql_fetch_array($selectBuild_id); $specificDevice = mysql_query("SELECT DISTINCT build_device_relationship.build_id, build_device_relationship.deviceID, devices.devicename FROM build_device_relationship, devices WHERE (build_device_relationship.build_id = '".$build_id['build_id']."') AND (build_device_relationship.deviceID = devices.deviceID)"); $echoDevice = mysql_fetch_array($specificDevice); echo $echoDevice['devicename']; echo "<select name='device' onchange=\"document.getElementById('sort').submit()\" onselect=\"select()\">"; echo "<option>Select Device</option>"; while($devicesearching=mysql_fetch_array($specificDevice)){ echo"<option>".$devicesearching['devicename']."</option>"; echo "</br>"; } echo "</select>"; $here = $_SESSION['device']; $_SESSION['device'] = $getdevice; echo $here; } print "\t</form>\n"; I am echoing everything that has been selected so I can see if it stores the variable...as of yet still cannot store variables well.. Link to comment https://forums.phpfreaks.com/topic/200220-url-retrieval/#findComment-1051117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.