Prev: FAQ Topic - Internationalisation and Localisation in javascript (2010-07-19)
Next: how to escape and pass html as variable
From: Kevin on 19 Jul 2010 08:59 Good Morning, My project consists of three: 1.main.html 2.paintTable.js 3.saveTable.js main.html just calls funtions #2 and #3. paintTable.js(void) consists of a bunch of document.write(...) that draw HTML. It takes no saveTable.js(void) makes a dummy XML, then performs a xmlDoc.save("some location.xml"); In this function, a new ActiveXObject("Microsoft.XMLDOM") is made, then it's saved once the updated table entries are saved. -------------------------------------------------------------------------------------------------------------------------------------------------------------------- Does this design make sense? How would you do it? Thanks, Kevin
From: Asen Bozhilov on 19 Jul 2010 10:58 Kevin wrote: > My project consists of three: > > 1.main.html > 2.paintTable.js > 3.saveTable.js > Does this design make sense? How would you do it? It depends on the meaning of the word "table". ..---------------------, | 1 | data | data | |---------------------| | 2 | data | data | |---------------------| | 3 | data | data | |---------------------| | 4 | data | data | `---------------------' The example above it is table too. One possible approach is: function Table() { this.rows = []; } Table.prototype.addRow = function() { //push the new row }; Table.prototype.draw = function () { //implement draw }; Table.prototype.toXML = function () { //return XML string }; Table.prototype.toHTML = function () { //return HTML string };
From: Kevin on 19 Jul 2010 12:38 Thanks, Asen. In particular, I'd like to know: Let's say I draw a button from a function called from main.html. If I change a button's functionality in a function, let's say by adding: ////////////////////// main.html paintPage(); makeAButton(); // end main.html makeAButton.js var aButton = document.getElementById("aButton"); aButton.onClick = saveToXML(); function saveToXML() { // save as XML file } ////////////////////// Will the button, "aButton," still have the saveToXML functionality at main.html?
From: Garrett Smith on 19 Jul 2010 15:25 On 2010-07-19 09:38 AM, Kevin wrote: > Thanks, Asen. > > In particular, I'd like to know: > > Let's say I draw a button from a function called from main.html. If I > change a button's functionality in a function, let's say by adding: > > ////////////////////// > > main.html > > paintPage(); > makeAButton(); > > // end main.html > > makeAButton.js > > var aButton = document.getElementById("aButton"); > aButton.onClick = saveToXML(); > Careful, it's `onclick`, not `onClick`. > function saveToXML() > { > // save as XML file The `this` value for this function call is supplied by the caller. It is the base object of the caller that in your case, is getting supplied by the "onclick" handler, which will be `aButton` (this === aButton). > } > ////////////////////// > > Will the button, "aButton," still have the saveToXML functionality at > main.html? If `saveToXML` is defined when the onclick is assigned, then the reference will be retained. -- Garrett
From: Kevin on 20 Jul 2010 12:37
Thank you, Garrett. > If `saveToXML` is defined when the onclick is assigned, then the > reference will be retained. I've tried these three statements separately, but none work for me. -------------------------------------------------------------------------------- function saveXML2(StringQuery) { var myButton = document.getElementsByName("saveButton") [0].childNodes[0]; myButton.onclick = print(); // myButton.onclick = new Function( "print()"); // myButton.onclick = print; } function print() { alert("print"); } ------------------------------------------------------------------------------------------ Thank you, Kevin |