Reputation: 759
Everytime I define a new Element with Prototype such as:
var iframe = new Element('iframe', {
name: 'preview_frame',
id: 'preview_frame',
src: 'form/' + formID + '?prev',
allowtransparency: true,
frameborder: 0
})
when I include the 'name' field in the list of attributes I get a DOM Exception 5
However when I do this:
var iframe = new Element('iframe', {
id: 'preview_frame',
src: 'form/' + formID + '?prev',
allowtransparency: true,
frameborder: 0
})
iframe.name = 'preview_frame';
Then I don't get the error.
Upvotes: 0
Views: 312
Reputation: 21
In your browser, "name" may be a reserved word in JavaScript (or stepping on another property).
In order to specify an object property for a reserved word in an object-literal declaration, put it in quotes, like this:
var iframe = new Element('iframe', {
"name": 'preview_frame',
"id": 'preview_frame',
"src": 'form/' + formID + '?prev',
"allowtransparency": true,
"frameborder": 0
})
Note that while you don't have to put ALL your properties in quotes, you can. See the Mozilla doc on reserved words on how to get around it: Mozilla JS Reserved Words
Upvotes: 2