passing arguments through multiple functions
Posted: Wed Nov 15, 2006 11:22 am
feyd | Please use
the whole thing is kicked off with
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);
}
}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]