15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2 ✦ Window and Frame Objects (Chapter 16)<br />

// Initialize by setting form elements from passed data<br />

function init() {<br />

if (window.dialogArguments) {<br />

var args = window.dialogArguments<br />

var form = document.prefs<br />

if (args[“name”]) {<br />

form.name.value = args[“name”]<br />

}<br />

if (args[“bgColor”]) {<br />

setSelected(form.bgColor, args[“bgColor”])<br />

}<br />

if (args[“textColor”]) {<br />

setSelected(form.textColor, args[“textColor”])<br />

}<br />

if (args[“h1Size”]) {<br />

setSelected(form.h1Size, args[“h1Size”])<br />

}<br />

}<br />

}<br />

// Utility function to set a SELECT element to one value<br />

function setSelected(select, value) {<br />

for (var i = 0; i < select.options.length; i++) {<br />

if (select.options[i].value == value) {<br />

select.selectedIndex = i<br />

break<br />

}<br />

}<br />

return<br />

}<br />

// Utility function to accept a press of the<br />

// Enter key in the text field as a click of OK<br />

function checkEnter() {<br />

if (window.event.keyCode == 13) {<br />

handleOK()<br />

}<br />

}<br />

<br />

<br />

<br />

Web Site Preferences<br />

<br />

<br />

<br />

<br />

Enter your first name:<br />

<br />

<br />

Select a background color:<br />

<br />

Beige<br />

Antique White<br />

Continued<br />

181<br />

windowObject.showModalDialog()

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

Saved successfully!

Ooh no, something went wrong!