Re: cloneNode() not getting script tag content





chippy wrote:


With the script tags I am filling out a javascript associative array:

				<script language="javascript" type="text/javascript">
						fieldData["IDAEA1VIDAFA1V4"]
						= {
						   DivID: "sic_code_4sic_code_or_filing_number",
						   ID:   "IDATE0VIDAUE0V4",
						   Size: "3",
						   Type: "xsd:string",
						   Enum: "false",
						   minLength: "",
						   maxLength: "",
						   Length: "3",
						   minInclusive: "",
						   maxInclusive: "",
						   Pattern: "[A-Z0-9]{3}",
						   Enumeration: ""};
				</script>


With the sID I am also able to reference the appropriate index of the array. The array contains information that I use for validating the input. Once I have a copy of the element, I can use the RegEx replace to make all of the id's and the javascript (the array) unique.

But if that array (that looks like a JavaScript object to me) is a global variable then simply manipulate it with your code, don't try to rely on DOM node cloning to manipulate/copy JavaScript data structures you control yourself.


I guess the bottom line is that I need some way to copy the elements I
need without doing it by reference (because then when I make changes to
the copied element the changes also go into the element I copied from).


I have tried to use a copy function like this:

function copy_obj(o) {
    var c = new Object();

    for (var e in o) {
      c[e] = o[e];
    }
    return c;
}

But you can do e.g.

var fieldData = {};
fieldData["IDAEA1VIDAFA1V4"]
						= {
						   DivID: "sic_code_4sic_code_or_filing_number",
						   ID:   "IDATE0VIDAUE0V4",
						   Size: "3",
						   Type: "xsd:string",
						   Enum: "false",
						   minLength: "",
						   maxLength: "",
						   Length: "3",
						   minInclusive: "",
						   maxInclusive: "",
						   Pattern: "[A-Z0-9]{3}",
						   Enumeration: ""};

function copy_obj(o) {
    var c = new Object();

    for (var e in o) {
      c[e] = o[e];
    }
    return c;
}

fieldData['newId'] = copy_obj(fieldData["IDAEA1VIDAFA1V4"]);
fieldData['newId'].ID = 'newId';

As said, I would not mix your script data structure manipulation with DOM manipulation. If you simply keep track of any stuff in fieldData then your script can always add properties there and manipulate subproperties without any need that the browser supports cloning inline script elements and executing the cloned code when the cloned script element is being inserted into the document. That approach is a rather fragile.

--

	Martin Honnen
	http://JavaScript.FAQTs.com/
.



Relevant Pages

  • RE: 2nd table need to add more fields other than from the 1st tabl
    ... You will not need to use an array. ... Another would be to construct either an append or an update ... > to manipulate them. ... >>> fields item names, prices and the second table includes item names, prices, ...
    (microsoft.public.access.modulesdaovba)
  • Re: Writing Array To A Named Range
    ... depending on what happens in the array, which could be a very powerful ... "Dave Peterson" wrote: ... manipulate the data in an array -- not in the range: ... Dim CompetitorOptionsArray As Variant ...
    (microsoft.public.excel.programming)
  • Re: Binary File I/O
    ... > sufficiently to know if binary data sequences can be manipulated. ... > can be manipulated as Array objects (with Unicode elements? ... are a range of bitwise operators in the language to manipulate the data ... String objects can also be used in this respect Each character can ...
    (microsoft.public.scripting.jscript)
  • Re: Examples of Using VBA, ODBC, and mysql
    ... Do you get a recordset? ... > connection to my database but I am not really that familiar ... > with how to manipulate the data. ... > I am interested in capturing the data into a variable or an array ...
    (microsoft.public.excel.programming)