Javascript/Ajax (using Agent)/PHP

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Javascript/Ajax (using Agent)/PHP

Post by Nunners »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm trying to get an ajax function working, but am having problems with the javascript side of things - I think.

The error I get is:
[quote]Error: uncaught exception: [Exception... "Index or size is negative or greater than the allowed amount"  code: "1" nsresult: "0x80530001 (NS_ERROR_DOM_INDEX_SIZE_ERR)"  location: "script.php Line: 80"][/quote]

This is the whole script (php and all)....

Code: Select all

<?php
require_once("db.php");

$db = db_connect();

login_check_permission($db,"add");

function GetAccountList ($string) {
	global $db;
	$result = db_query("SELECT accountRef FROM family WHERE active='y' AND accountRef LIKE ".db_sql($string)." ORDER BY accountRef ASC",$db);
	$list_array = array();
	$count = 0;
	while ($row = db_fetch_array($result)) {
		$list_array[$count] = $row["accountRef"];
		$count++;
	}
	return array_values($list_array);
}

include_once("../includes/agent.php");
$agent->init();
?>
<html>
	<head>
		<title></title>
		<link href="/css/styles.css" rel="stylesheet" media="screen">
		<script language="javascript">
		<!--
		function formsubmit () {
			document.form.action.value="save";
			document.form.submit();
		}

		-->
		</script>
	</head>
	<body>
		<form action="receipt_create.php" method="GET" name="form">
			<input type="hidden" name="action" value="search">
			<table width="700" border="0" cellspacing="1" cellpadding="2">
				<tr>
					<td nowrap align="left"><span class="header">Receipt New</span></td>
					<td align="left"></td>
					<td nowrap align="right"></td>
					<td align="right" colspan="3"></td>
				</tr>
				<tr>
					<td colspan="6" nowrap align="right">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="6" nowrap align="left"><?=display_error(true)?></td>
				</tr>
				<tr>
					<td colspan="6" nowrap align="right">&nbsp;</td>
				</tr>
			<tr>
					<td nowrap align="right"><strong>Date:</strong></td>
					<td align="left"><input type="text" name="date" value='<?=$_GET["date"] ? $_GET["date"] : date("d/m/Y")?>' size="10"></td>
					<td nowrap align="right"><strong>Account Ref:</strong></td>
					<td align="left">
						<input type="text" name="accountRef" id="accountRef" onkeyup="GetAccountList();return false;" autocomplete="off">
						<select id="results" style="VISIBILITY: hidden" onclick="MatchSelected(this);" ></select>

		<script language="javascript">
		<!--
		var list = document.getElementById("results");

		function GetAccountList() {
			var accountRef = document.getElementById('accountRef').value;
			agent.call('','GetAccountList','callback_GetAccountList',accountRef);
		}
		
		function callback_GetAccountList(listArray) {
			list.style.visibility = "visible";
			list.options.length = 0; //reset the states dropdown
			list.size = listArray.length;
			for (var i = 0; i < listArray.length; i++) {
				list.options[list.options.length] = new Option(listArray[i]);
			}
		}

		function MatchSelected(results) {
			var accountRef = document.getElementById("accountRef");
			accountRef.value = results.options[results.selectedIndex].text;
			GetAccountList(accountRef.value);
		}
		-->
		</script>

					</td>
					<td align="right"><strong>Amount:</strong></td>
					<td>&pound;<input type="text" name="amount" size="10" maxlength="10" value="<?=$_GET["amount"]?>"></td>
				</tr>
				<tr>
					<td colspan="6" nowrap align="right">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="4" align="left"></td>
					<td colspan="2" align="right"><input type="image" src="/images/b_save.gif"></td>
				</tr>
			</table>
		</form>
	</body>
</html>

Is anyone able to point out where I'm going wrong?

Cheers
Nunners


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply