15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1 ✦ Generic HTML Element Objects (Chapter 15)<br />

appended to the document’s form element. Finally, the outerHTML of the new element<br />

is displayed in its field. Notice that except for the NAME and ID attributes, all<br />

others are copied. This includes style sheet attributes and event handlers. To prove<br />

that the event handler works in the new elements, you can add a space to any one<br />

of them and press Tab to trigger the onChange event handler that changes the content<br />

to all uppercase characters.<br />

Listing 15-29: Using the mergeAttributes() Method<br />

<br />

<br />

mergeAttributes() Method<br />

<br />

function doMerge(form) {<br />

var newPElem = document.createElement(“P”)<br />

var newInputElem = document.createElement(“INPUT”)<br />

newInputElem.id = newInputElem.uniqueID<br />

newInputElem.mergeAttributes(form.field1)<br />

newPElem.appendChild(newInputElem)<br />

form.appendChild(newPElem)<br />

newInputElem.value = newInputElem.outerHTML<br />

}<br />

// called by onChange event handler of fields<br />

function upperMe(field) {<br />

field.value = field.value.toUpperCase()<br />

}<br />

<br />

<br />

<br />

mergeAttributes() Method<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

normalize()<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓<br />

79<br />

elementObject.normalize()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!