suttercain Posted August 9, 2007 Share Posted August 9, 2007 Hi everyone, I have a drop down list that is populated via MySQL. Once an item is selected a second drop down appears, again populated by MySQL. I know how to keep the value for the first drop down, if the page is reloaded.... but the second one is where I am having the issue. Is it possible to have a page reload and echo not only the first dropdown value, but also the second within the <select> tags? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/64108-drop-down-based-on-first-working-but-how-do-i-keep-the-value-if-page-reloaded/ Share on other sites More sharing options...
lemmin Posted August 9, 2007 Share Posted August 9, 2007 When you say "reload," do you mean that you are submitting the data or pressing refresh? If you are submitting you data it should be easy to grab it from the $_GET or $_POST arrays and reprint depending on what was submitted. Quote Link to comment https://forums.phpfreaks.com/topic/64108-drop-down-based-on-first-working-but-how-do-i-keep-the-value-if-page-reloaded/#findComment-319495 Share on other sites More sharing options...
suttercain Posted August 9, 2007 Author Share Posted August 9, 2007 Ideally I would like it to work if the user either hit submit or if the page was reloaded. I am attempting this using sessions. Here is the actually demo: http://shannoncronin.com/dropdown.php Here is the code: dropdown.php <?php session_start; ?> <html> <head> <script src="js/selectuser.js"></script> </head> <body> <select name="comics" onchange="showUser(this.value)"> <?php require ('get_connected.php'); //These Seven Lines of Code Populate the comic List from the Database: Do not alter. $query = mysql_query("SELECT distinct(title) FROM comics ORDER BY title"); echo "<option value=\"0\" selected=\"selected\">Select a Comic Title</option>"; while ($row = mysql_fetch_array($query)) { $_SESSION['title'] = $row['title']; echo "<option value=\"" .$_SESSION['title']. "\">" .$_SESSION['title']. "</option>"; } ?> </select><br /> <div id="txtHint"></div> <!--The DIV txtHint Populates the drop down. Do not change. --></p> <br /> <input type="submit" name="submit" value="submit" /> </form> </body> </html> selectuser.js // JavaScript Document var xmlHttp function showUser(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="../getuser.php" url=url+"?q="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("txtHint").innerHTML=xmlHttp.responseText } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } getuser.php <?php session_start(); $q=$_GET["q"]; require ('get_connected.php'); $sql="SELECT * FROM comics WHERE title = '".$q."' ORDER BY issue_number"; //ISSUE SELECT $result = mysql_query($sql); echo "<br /><label for=\"testinput\"><b>Select an Issue Number</b></label>"; echo "<br>"; echo "<select name=\"issue\">"; echo "<option value=\"NULL\" selected=\"selected\">Select An Issue Number</option>"; while($row2 = mysql_fetch_array($result)) { $_SESSION['issue_number'] = $row2['issue_number']; echo "<option value=\"" .$_SESSION['issue_number']. "\"># " .$_SESSION['issue_number']. "</option>"; } echo "</select>"; echo "<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64108-drop-down-based-on-first-working-but-how-do-i-keep-the-value-if-page-reloaded/#findComment-319507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.