Link to home
Start Free TrialLog in
Avatar of astrohelp
astrohelp

asked on

Calling a javascript function in an ajax page

I have a page that I use some ajax to call another page and place the results into the innerhtml of a div. I want to be able to call a javascript function from the returned html. Is this possible?
SOLUTION
Avatar of netsmithcentral
netsmithcentral
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of astrohelp
astrohelp

ASKER

Hmm, I am a little rusty with js, so I think it will be better for everyone if I just put up a sample of my code.

------------------------index--------------------------------
var ro;

var http = createRequestObject();
var urlid = "";
var urlid_ext = "";

function createRequestObject() {

    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

function sndReq2() {

            //urlid = url.substring(0,url.indexOf("."));

            urlid_ext = "/poll.php?action=display";

            http.open('get', urlid_ext);
            http.onreadystatechange = handleResponse2;
          http.send(null);

}

function handleResponse2() {
    if(http.readyState == 4){
        var response = http.responseText;
        //var update = new Array();

            //update = response.split('|');
           //response = response.replace('%0A','*');

//alert(response);
document.getElementById("pollarea").innerHTML = response;
  }
}
--------------------------------------------------------------------------------

-----------------------------requested page----------------------------------
echo("<input type=radio onclick='function()' name=opts value=" . $poll_order . ">" . $opts . "<br>");
----------------------------------------------------------------------------------

I would like the onclick in the requested page to call a function on the index page.

thanks again
You can register event handlers to items in the DOM by referencing them as properties.
   eg - document.getElementById('pollarea').childNodes[childNodes.length].onclick = doSomething;  <--- notice you don't put () on the function as that would register the result to to the event, not the function itself.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
...

ok...

I was having a bad day when I wrote this question, It was one of those days when the obvious seems impossible. I am going to award the points to both of you, I have no idea why this was a problem to me last night!

thanks!!!