From: Kevin on
Howdy,

How can I reference a function and include a parameter from a
javascript?

I need to include two inputs, xmlDoc and location, for my saveFile
function. Without those inputs, my saveFile won’t work.

var myButton = document.getElementsByName(“saveButton”)[0];
myButton.onclick = saveFile(xmlDoc,location);

Note that the code above does not work.

Thank you,
Kevin


From: Matt Kruse on
On May 26, 4:56 pm, Kevin <kevin.m.mered...(a)gmail.com> wrote:
> myButton.onclick = saveFile(xmlDoc,location);

This will execute saveFile with those two arguments, and assign the
result to onclick.

You want:
myButton.onclick = function() { saveFile(xmlDoc,location); };

Matt Kruse
From: Kevin on
> You want:
> myButton.onclick = function() { saveFile(xmlDoc,location); };
>
> Matt Kruse

Hi Matt,

Thanks for your reply. When I call this javascript file (see snippet
below), it doesn't call "myButton.onclick = ..." because I don't
receive the alert, "saved changes to location."

function saveXML(xmlDoc, location)
{
var myButton = document.getElementsByName("saveButton")[0];
myButton.onclick = function() { saveFile(xmlDoc,location); };
}

function saveFile(xmlDoc, location)
{
xmlDoc.save(location);
alert("Saved changes to " + location);
}
From: nick on
On May 27, 9:38 am, Kevin <kevin.m.mered...(a)gmail.com> wrote:

> When I call this javascript file (see snippet
> below), it doesn't call "myButton.onclick = ..." because I don't
> receive the alert, "saved changes to location."

You should post an example with html included, otherwise it's
impossible to tell what's going on. If I had to guess I'd say you're
trying to assign the onclick attribute to an element that doesn't
exist yet (i.e. dom not ready when script runs).

First, though, check for error messages, and check that
document.getElementsByName("saveButton") actually has a length.
From: Kevin on
Two functions:

function drawHotLinkButton(name) // onBodyLoad calls "paint the
screen," which calls drawHotLinkButton(name) to draw a button
// on the screen that opens a new
webpage, webpage.html?xml=something.xml, when the button's clicked.
{
document.write("<input name=\"" + name + "\" type=\"button\" \/
>");
}

function populateHotLinkButtons(xmlDoc) // this function adds the
onclick functionality to the button.
// note that I didn't set a
value in the drawHotLinkButton() above. I'm trying
// to add the button's value
in this function so that I can set it based on the XML DOM
{
var XMLnode = xmlDoc.getElementsByTagName("Name")
[0].childNodes[0];
var HTMLnode = document.getElementsByName("Name")[0];
HTMLnode.value = XMLnode.nodeValue;

HTMLnode.onclick = function() { window.location="webpage.html?xml="
+ value + ".xml" };
}