chippy wrote:
[color=blue]
> 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.[/color]
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.
[color=blue]
> 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;
> }[/color]
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/