...

XML filtering predicate operator called on incompatible function..

cyphix
08-17-2007, 02:07 AM
Can anyone tell me what I'm doing wrong here?

HTML


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Lottery Selector</title>
<script language="javascript" type="text/javascript" src="javascript.js"></script>
</head>

<body bgcolor="#ffffff">

<form name="form1">
<input type="button" name="generate" value="Generate Lottery Selections" onclick="generate_numbers();" />
&nbsp;
<span id="selections">
<input type="text" name="selection_field" size="30" />
</span>
</form>

</body>
</html>


JavaScript:


function so_clearInnerHTML(obj) {
while(obj.firstChild) obj.removeChild(obj.firstChild);
}

var xmlHttp

function generate_numbers()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="gadget.php";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
var mr_data = xmlHttp.responseText;
so_clearInnerHTML(document.getElementById("selections"));
var foo = document.getElementById.("selections"); // This is the problem line
e_node = document.createElement('text');
e_node.setAttribute('name','selection_field');
e_node.setAttribute('size',30);
e_node.setAttribute('value',mr_data);
foo.appendChild(e_node);
}
}

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;
}


Cheers!

A1ien51
08-17-2007, 03:04 AM
what is with the period in there?

document.getElementById.("selections");

Remove that...

If you have not done so already. Install Firefox and than install the Firebug extension http://www.getFirebug.com, it will make debugging JavaScript a lot easier.

Eric

cyphix
08-17-2007, 03:29 AM
Hehe thanks that fixed it... silly mistake by me! But now for some reason I am not getting the result I was hopping for.... the box just disappears & doesn't come back with the data I was trying to put into it.... I had this working fine using innerHTML with FF; but it didn't work with IE properly (on the second push of the button) it wouldn't update again..... it would always stay the same value so I tried doing it this way.

rwedge
08-17-2007, 07:51 AM
Since you are creating an input element
e_node = document.createElement('text');

You should be using 'input'

e_node = document.createElement('input');
e_node.setAttribute('type','text');
You use 'var xmlHttp' twice. Drop the var in the GetXmlHttpObject function as xmlHttp needs to be global to be used by other functionsvar xmlHttp;

function generate_numbers()
.....
function GetXmlHttpObject()
{
var xmlHttp=null;
Since you do not check the response , you may want to alert it to verify you are getting what you expect.

cyphix
08-17-2007, 03:23 PM
Hehe yeah.. I just worked out about the input tag problem..... another silly mistake by me hehe.... cheers!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum