PDA

View Full Version : AJAX Javascript Error


daffy_dowden
12-05-2005, 02:45 PM
Hi, Not entirely sure whether I've posted to the correct forum as this topic contains a little ASP as well.

Basically I'm trying to create an ap which will display an employee number or list of employee numbers when a name is typed. The actual back end function has already been created and works when used with static pages.

I've been trying to use the CPaint Ajax toolkit (http://cpaint.booleansystems.com/) to accomplish this and have written a little bit of code in asp. A few of the function i've written work but this one is slightly more ambitious as I'm attempting to fill an area of the screen with html returned from the function as opposed to just a text area which the functions use.

I'm not sure if that made that much sense, if not ask but I think its best looking at the code.

Main html Page

...in the head...
<script type="text/javascript" src="cpaint2.inc.js"></script>
<script type="text/javascript">
var cp = new cpaint();
cp.set_transfer_mode('get');
cp.set_response_type('xml');
//cp.set_debug(true);

function addName() {
cp.call('calculator.asp', 'gedPeople', response, document.getElementById('person').value);
}
function addEmail() {
cp.call('calculator.asp', 'gedEmail', response, document.getElementById('person').value);
}

function addGedNum() {
cp.call('calculator.asp', 'gedID', response2, document.getElementById('person').value);
}

function response(result) {
document.getElementById('result').value = result.getElementsByTagName('ajaxResponse').item(0).firstChild.data;
}

function response2(result) {
document.getElementById('result2').innerHtml = result2.getElementsByTagName('ajaxResponse').item(0).firstChild.data;
}

</script>
... in the body...
<input name="num1" type="text" id="person" size="30">
<input type="button" name="Equals2" value="gedNum" onClick="addGedNum();">
<div id="result2" id="result2" >&nbsp;</div>

In the ASP file

<!---#include virtual="/ntcomponents/sitelocator.asp" --> <!--File containg GED functions -->

<!--#include file="cpaint2.inc.asp"-->
<%
set cp = new cpaint
cp.register("gedID")
cp.start("")
cp.return_data

function gedID(UID)
cp.set_id "response2"
UID = GedGetNameString(UID, "S")
cp.set_data UID
add = vbnull
end function
%>


When I press the submit button on the main html page I get an error in FF saying that results2 isn't defined. Any ideas how i can solve this? pretty sure it can't be too hard, unfortunately my JS isn't too hot (There's one for the New years resolution list!)

Let me know if you require any more information.

Many Thanks!
Richard

A1ien51
12-05-2005, 05:02 PM
without knowing the framework I would assume the line:

document.getElementById('result2').innerHtml = result2.getElementsByTagName

should be

document.getElementById('result2').innerHtml = result.getElementsByTagName

Eric

daffy_dowden
12-05-2005, 05:10 PM
Hi,
Thanks for the reply. I should have spotted that one!
It's solved the error I was getting but now I'm getting a new one:

Error: result.getElementsByTagName("ajaxResponse").item(0).firstChild has no properties

Is that to do with the returned data from the external function?

Thanks,
Richard

A1ien51
12-05-2005, 08:17 PM
You look at this:
http://cpaint.booleansystems.com/doc/usage.frontend.page3.html

Eric