Greaser9780 Posted March 2, 2007 Share Posted March 2, 2007 Here is my select box that calls the js: <html> <head> <script src="selectuser.js"></script> </head> <body> <form> <select name="users" onchange="showUser(this.value)"> <option>QB</option> <option>WR</option> <option>RB</option> <option>TE</option> <option>PK</option> <option>DF</option> </select> </FORM> <div id="txtHint"> </div> </BODY> </html> Here is the java: var xmlHttpfunction ;showUser(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") } 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; } Here is what it is supposed to show: <?php $q=$_GET["q"]; require("db.php"); $sql="SELECT * FROM players WHERE position = '".$q."'"; $result = mysql_query($sql); ?> <html> <head> </head> <body> <form action="select.php" method="post"> Team name:<input type='text' name='name'> Password:<input type='password' name='pass'> Comment:<input type='text' name='com' maxlength='80'> <select name="playername"> <?php while($row = mysql_fetch_array($result)) { echo "<option value='" . $row['name'] . "'>" . $row['name'] . "</option>"; } ?> </select> <input type="submit" name="submit" value="select"> </form> </body> </html> Any clues why I keep getting these errors Link to comment https://forums.phpfreaks.com/topic/40848-showuser-not-defined/ Share on other sites More sharing options...
ScotDiddle Posted March 2, 2007 Share Posted March 2, 2007 Greaser9780, I got it to work with the following files... Try them out and let us know. Scot L. Diddle, Richmond VA test2.php <html> <head> <style> div#txtHint { font-weight:bold; } </style> <script src="/javascript/showUser.js"></script> </head> <body> <form> <select name="users" onchange="showUser(this.value)"> <option>QB</option> <option>WR</option> <option>RB</option> <option>TE</option> <option>PK</option> <option>DF</option> </select> </FORM> <div id="txtHint"> </div> </BODY> </html> showUser.js ( Called from test2.php, it lives in a folder called javascript/ ) var xmlHttp function showUser(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="showUser.php" url=url+"?"+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; } showUser.php ( Called form showUser.js ... modified, because I don't have your DB definitions... ) <?php $q=$_GET["q"]; // echo "\$q : " . $q; $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("MySQL", $con); $sql="SELECT * FROM user "; $result = mysql_query($sql); ?> <html> <head> </head> <body> <form action="select.php" method="post"> Team name:<input type='text' name='name'> Password:<input type='password' name='pass'> Comment:<input type='text' name='com' maxlength='80'> <select name="playername"> <?php while($row = mysql_fetch_array($result)) { echo "<option value='" . $row['0'] . "'>" . $row['1'] . "</option>"; } ?> </select> <input type="submit" name="submit" value="select"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/40848-showuser-not-defined/#findComment-198135 Share on other sites More sharing options...
Greaser9780 Posted March 3, 2007 Author Share Posted March 3, 2007 showUser.php is not getting the variable $q. Any clue how to force showUser to get Q. I need showUser.php to know which position was selected so it can send the proper query to show. Link to comment https://forums.phpfreaks.com/topic/40848-showuser-not-defined/#findComment-198286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.