nezbo Posted March 19, 2008 Share Posted March 19, 2008 Hi all please can some one help me... I dont know javascript to well and i know aJax even less, i am looking to call a function that gets info from a database and then puts it in to a text box. i can do the textbox thing once have the info in Javascript but i dont know how to get it from PHP/MySql to javascript. i have looked all over the internet for a turotial and it has goven me a spliting headake... :'( here is my code so far : the javascript/ajax bit <script type="text/javascript"> function getStaffHours() { var theTotalHours1 = ajax.getElementById('thetotalhours', 'aJaxUserQ.php'); document.getElementById("staffHours1").value = theTotalHours1; } </script> the form bit echo "<select name='theUser' id='nameSelected' onchange='getStaffHours(this.value)'><option value=\"\"></option>"; the PHP bit (ajaxUserQ.php) <?php $getTheUser = mysql_query("SELECT * FROM person WHERE CallID = '" . $_COOKIE['user'] . "'"); while ($getTheUser2 = mysql_fetch_array($getTheUser)) { $userHours = $getTheUser2['contHours']; } ?> <div id='thetotalhours'><?php echo $userHours; ?></div> Link to comment https://forums.phpfreaks.com/topic/96925-newbe-help-please/ Share on other sites More sharing options...
nezbo Posted March 19, 2008 Author Share Posted March 19, 2008 my function now looks like this : <script type="text/javascript"> function ajaxFunction(AJAXpage) { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById("nameSelected").value=xmlHttp.responseText; } } xmlHttp.open("GET","AJAXpage",true); xmlHttp.send(null); } function getStaffHours(AJAXpage) { ajaxFunction("aJaxUserQ.php"); } </script> and it still dose nothing :'( I thin it might be some thing to do with the php page not giving anything out. Link to comment https://forums.phpfreaks.com/topic/96925-newbe-help-please/#findComment-496000 Share on other sites More sharing options...
nezbo Posted March 19, 2008 Author Share Posted March 19, 2008 i think i may be nearly there.... I am not geting this comming back in to the text box... <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Object not found!</title><link rev="made" href="mailto:admin@localhost" /><style type="text/css"><!--/*--><![CDATA[/*><!--*/ body { color: #000000; background-color: #FFFFFF; } a:link { color: #0000CC; } p, address {margin-left: 3em;} span {font-size: smaller;}/*]]>*/--></style></head><body><h1>Object not found!</h1><p> The requested URL was not found on this server. The link on the <a href="http://localhost/call_Log/staffHours.php">referring page</a> seems to be wrong or outdated. Please inform the author of <a href="http://localhost/call_Log/staffHours.php">that page</a> about the error. </p><p>If you think this is a server error, please contactthe <a href="mailto:admin@localhost">webmaster</a>.</p><h2>Error 404</h2><address> <a href="/">localhost</a><br /> <span>03/19/08 17:03:17<br /> Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8d mod_autoindex_color PHP/5.2.1</span></address></body></html> and i am expacting just the number 37... here is my code again... function ajaxFunction(AJAXpage) { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById("staffHours1").value=xmlHttp.responseText; } } xmlHttp.open("GET","AJAXpage",true); xmlHttp.send(null); } function getStaffHours() { ajaxFunction("/aJaxUserQ.php"); } </script> and my php (if i run this on it's own it brings back the no 37) <?php include ("include/dbcon.php"); $getTheUser = mysql_query("SELECT * FROM person WHERE CallID = '" . $_COOKIE['user'] . "'"); while ($getTheUser2 = mysql_fetch_array($getTheUser)) { echo $userHours = $getTheUser2['contHours']; } ?> Link to comment https://forums.phpfreaks.com/topic/96925-newbe-help-please/#findComment-496022 Share on other sites More sharing options...
nezbo Posted March 19, 2008 Author Share Posted March 19, 2008 i think i have narrowed it down to not finding the file, but the file is in the same folder and is name correctly. i am going bolder by the second :'( here is my letest code : <script type="text/javascript"> function ajaxFunction(AJAXpage) { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById("staffHours1").value=xmlHttp.responseText; } } xmlHttp.open("GET","AJAXpage",true); xmlHttp.send(null); } function getStaffHours() { var theSelectedUser = document.getElementById("nameSelected").value; ajaxFunction("aJaxUserQ.php&nameSelected =" . theSelectedUser); } </script>code] Link to comment https://forums.phpfreaks.com/topic/96925-newbe-help-please/#findComment-496034 Share on other sites More sharing options...
korbinus Posted March 23, 2008 Share Posted March 23, 2008 Well, it's difficult to understand without trying it a little bit, but I just noticed a mistake in your last function. You wrote function getStaffHours() { var theSelectedUser = document.getElementById("nameSelected").value; ajaxFunction("aJaxUserQ.php&nameSelected =" . theSelectedUser); } but you should put a question mark (?) after your script extension, definitely not a paramter separator (&): function getStaffHours() { var theSelectedUser = document.getElementById("nameSelected").value; ajaxFunction("aJaxUserQ.php?nameSelected =" . theSelectedUser); } Link to comment https://forums.phpfreaks.com/topic/96925-newbe-help-please/#findComment-498713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.