passing arguments through multiple functions

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
obiron
Forum Newbie
Posts: 15
Joined: Fri Nov 10, 2006 4:50 am

passing arguments through multiple functions

Post by obiron »

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]


hey guys,

this is not so much PHP and general coding advice as I am using Ajax to update pages (calling php scripts to generate the innerHTML).

My web page is divided into four <DIV>s : 'main', 'lookup', 'messages' and 'additional' and different data needs to be sent to different parts of the screen, so the function that calls the function to create a new xmlhttrequest takes two arguments, the URL and the target div.

The function that creates the request and does the submit uses the url and passes the target onto the function that processes the results.

so the target argument has been passed through three separate functions.

I just have a feeling that there should be a better way to do this than playing pass the parcel.

Code: Select all

function fn_getStatic(tableName,targetframe)
{
  var url = "http://www.xxxxxxxxxx.co.uk/static.php?tablename=" + escape(tableName);
  loadXMLDoc(url,targetframe);
}

function loadXMLDoc(url,targetframe)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = pdatePage(targetframe);
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {updatePage(targetframe);};
            req.open("GET", url, true);
            req.send();
        }
    }
}

function updatePage(targetframe)
{
   if (req.readyState == 4) {
     if (req.status == 200) {
       var response = req.responseText;
       document.getElementById(targetframe).value = response;
       document.getElementById(targetframe).innerHTML =
         response.replace(/\n/g, "");
     } else
       alert("status is " + req.status);
   }
}
the whole thing is kicked off with

Code: Select all

<?php
print "<DIV onclick=\"fn_getStatic('MediaCode','main');\">Media Code</DIV>";
?>

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