From: Kevin on 26 May 2010 17:56 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 wont 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 26 May 2010 18:11 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 27 May 2010 09:38 > 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 27 May 2010 20:04 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 7 Jun 2010 00:16 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" }; }
|
Next
|
Last
Pages: 1 2 Prev: Find all event listeners on a link, including delegatedlisteners? Next: Firefox cache issue |