june_c21 Posted January 21, 2008 Share Posted January 21, 2008 hi, i try to run this code but when i code on the select menu, there is no information display. can someone tell me what's the mistake? html page <html> <head> <script src="selectuser.js"></script> </head> <body><form> <table width="497" border="0"> <tr> <td width="284">Staff No </td> <td width="203"><input type="text" name="textfield"></td> </tr> <tr> <td>GF</td> <td><input type="text" name="textfield2"></td> </tr> <tr> <td>Designation</td> <td><input type="text" name="textfield3"></td> </tr> <tr> <td>Date Of Borrow </td> <td><input type="text" name="textfield4"></td> </tr> <tr> <td>Tools</td> <td><select name="tool_list" onChange="showUser(this.value)"> <option value="1">Allen Keys (2MM)</option> <option value="2">Allen Keys (2.5MM)</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select></td> </tr> <tr> <td colspan="2"><p> <div id="txtHint"><b>Info will be listed here.</b></div> </p> </td> </tr> <tr> <td>Quantity</td> <td><input type="text" name="textfield5"></td> </tr> <tr> <td>Status</td> <td><select name="select"> <option>Borrow</option> </select> </td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form></body> </html> javascript var xmlHttpfunction showUser(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="getuser.php" url=url+"?id="+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; } php code <?php $id=$_GET["id"]; $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'tool'; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); $sql="SELECT * FROM tool_list WHERE id = '".$id."'"; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>ID</th> <th>Title</th> <th>Model</th> <th>Capacity</th> <th>Quantity</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[0] . "</td>"; echo "<td>" . $row[1] . "</td>"; echo "<td>" . $row[2] . "</td>"; echo "<td>" . $row[3] . "</td>"; echo "<td>" . $row[4] . "</td>"; echo "</tr>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 21, 2008 Share Posted January 21, 2008 Mind using tags? var xmlHttpfunction showUser(str) Should be: var xmlHttp; function showUser(str) xmlHttp=GetXmlHttpObject() Should be: (just testing up to IE 7.0) xmlHttp = (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") Uh, what's the point of checking both of those? if (xmlHttp.readyState==4) Quote Link to comment Share on other sites More sharing options...
june_c21 Posted January 21, 2008 Author Share Posted January 21, 2008 thanks... another part is how to pull the value from database to put in my pull down menu option so that i don't have to write it out. I got 500++ options. Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 21, 2008 Share Posted January 21, 2008 You have an error near var xmlHttpfunction showUser(str) { use var xmlHttpfunction ; function showUser(str) { this is working at my end. Quote Link to comment Share on other sites More sharing options...
june_c21 Posted January 21, 2008 Author Share Posted January 21, 2008 thanks... another part is how to pull the value from database to put in my pull down menu option so that i don't have to write it out. I got 500++ options. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 21, 2008 Share Posted January 21, 2008 Hello, Could you update your original post with the updated code and in tags? If you can't edit that, make a reply with those information updated. Thanks, Ken Quote Link to comment Share on other sites More sharing options...
june_c21 Posted January 21, 2008 Author Share Posted January 21, 2008 hi, sorry... i just update my code. can anyone help with the the listing the option value from database? html page <html> <head> <script src="selectuser.js"></script> </head> <body><form> <table width="497" border="0"> <tr> <td width="284">Staff No </td> <td width="203"><input type="text" name="textfield"></td> </tr> <tr> <td>GF</td> <td><input type="text" name="textfield2"></td> </tr> <tr> <td>Designation</td> <td><input type="text" name="textfield3"></td> </tr> <tr> <td>Date Of Borrow </td> <td><input type="text" name="textfield4"></td> </tr> <tr> <td>Tools</td> <td><select name="tool_list" onChange="showUser(this.value)"> <option value="1">Allen Keys (2MM)</option> <option value="2">Allen Keys (2.5MM)</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> </select></td> </tr> <tr> <td colspan="2"><p> <div id="txtHint">Info will be listed here.</div> </p> </td> </tr> <tr> <td>Quantity</td> <td><input type="text" name="textfield5"></td> </tr> <tr> <td>Status</td> <td><select name="select"> <option>Borrow</option> </select> </td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form></body> </html> javascipt var xmlHttp; function showUser(str) { xmlHttp = (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="getuser.php" url=url+"?id="+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; } php <?php $id=$_GET["id"]; $host = 'localhost'; $user = 'root'; $password = 'admin'; $dbase = 'tool'; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); $sql="SELECT * FROM tool_list WHERE id = '".$id."'"; $result = mysql_query($sql); echo "<table border='1'> <tr> <th>ID</th> <th>Title</th> <th>Model</th> <th>Capacity</th> <th>Quantity</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[0] . "</td>"; echo "<td>" . $row[1] . "</td>"; echo "<td>" . $row[2] . "</td>"; echo "<td>" . $row[3] . "</td>"; echo "<td>" . $row[4] . "</td>"; echo "</tr>"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 21, 2008 Share Posted January 21, 2008 do u mean u want the code to populate the dropdown with the databse values ? Quote Link to comment Share on other sites More sharing options...
june_c21 Posted January 21, 2008 Author Share Posted January 21, 2008 do u mean u want the code to populate the dropdown with the databse values ? yes. how to write that code? Quote Link to comment Share on other sites More sharing options...
june_c21 Posted January 21, 2008 Author Share Posted January 21, 2008 pls help........... Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 21, 2008 Share Posted January 21, 2008 Remove the html : <option value="1">Allen Keys (2MM)</option> <option value="2">Allen Keys (2.5MM)</option> <option value="3">Glenn Quagmire</option> <option value="4">Joseph Swanson</option> and add the php code : <?php $host = 'localhost'; $user = 'username'; $password = 'password'; $dbase = 'db_name'; $dblink = mysql_connect($host,$user,$password); mysql_select_db($dbase,$dblink); $sql="SELECT * FROM tablename "; $result = mysql_query($sql); while($arr=mysql_fetch_assoc($result)){ echo "<option value='".$arr['id']."'>".$arr['name']."</option>"; } ?> and change the sql according to your need. rgds Sharad Quote Link to comment Share on other sites More sharing options...
priti Posted January 21, 2008 Share Posted January 21, 2008 hi, check script here http://ajaxforums.net/index.php?PHPSESSID=b71f530822e329a94da8f17e0397cdf6&topic=858.0 regards Quote Link to comment Share on other sites More sharing options...
pdkv2 Posted January 21, 2008 Share Posted January 21, 2008 Thanks for the link priti Quote Link to comment Share on other sites More sharing options...
priti Posted January 22, 2008 Share Posted January 22, 2008 Thanks for the link priti glad to share knowledge :-) 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.