Jump to content

newbe help please :'(


nezbo

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.