unistake Posted August 26, 2009 Share Posted August 26, 2009 Hi all, I have a select box that works fine in normal html if i list the mysql values by hand, however when I try to get the values from a mysql database using the code below, the script DOES NOT work in IE and some other browsers, however it DOES work in Mozilla. Do you know where I have gone wrong? Thanks <?php echo " <select name='users' style='margin-left:-10px; padding:7px; width:270px; height:40px; background-color:#C0DB5A; border:2px solid #888888; font-size:16px;'> <option>1. select...</option>"; while ($row = mysql_fetch_assoc($result)) { extract($row); echo "<option value='$bookmaker' onClick=\"showUser(this.value)\">$bookmaker</option>"; } echo "</select>"; ?> p.s - when testing any website script, what browser is best to use? I use mozilla, however I am not sure if this is right because of problems like above! Quote Link to comment Share on other sites More sharing options...
ram4nd Posted August 26, 2009 Share Posted August 26, 2009 dont use single quotes in html code, can we see the whole code Quote Link to comment Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 Firefox (Mozilla) is a good option Opera is also a good option but I generally stick to Firefox because of add-ons already available (like FireBug). Quote Link to comment Share on other sites More sharing options...
unistake Posted August 26, 2009 Author Share Posted August 26, 2009 This is the full PHP code that is included in another PHP page that contains <script type="text/javascript" src="selectuser.js"></script> the above javascript works as it should when using it with just a HTML version of the select box below. The full PHP code is here // included PHP code //// <?php $con = mysql_connect('localhost', 'user', 'password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db", $con); $sql="SELECT * FROM bookmakers"; $result = mysql_query($sql); echo " <select name='users' style='margin-left:-10px; padding:7px; width:270px; height:40px; background-color:#C0DB5A; border:2px solid #888888; font-size:16px;'> <option>1. select...</option>"; while ($row = mysql_fetch_assoc($result)) { extract($row); echo "<option value='$bookmaker' onClick=\"showUser(this.value)\">$bookmaker</option>"; } echo "</select>"; ?> /// main.php // <?php include("selectoption.php"); ?> <div id="txtHint"><p>select an option from above</div> // 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) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } Quote Link to comment Share on other sites More sharing options...
unistake Posted August 26, 2009 Author Share Posted August 26, 2009 also the getuser.php script is <?php $q=$_GET["q"]; include("login.inc"); mysql_select_db("$database", $con); $sql="SELECT * FROM bookmakers WHERE bookmaker = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo $row['bookmaker']; echo $row['bonus']; } ?> Quote Link to comment Share on other sites More sharing options...
unistake Posted August 26, 2009 Author Share Posted August 26, 2009 just got it working! Had to just change every ' in the php to \". and it works ! Quote Link to comment Share on other sites More sharing options...
unistake Posted August 26, 2009 Author Share Posted August 26, 2009 this problem has re-opened! It seemed that it worked at one point, but it has reverted to going back to as I explained. Quote Link to comment 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.