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.

166<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Listing 16-28: Printing Control<br />

<br />

<br />

Print()<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

If you don’t like some facet of the printed output, blame the browser’s print<br />

engine, and not <strong>JavaScript</strong>. The print() method merely invokes the browser’s regular<br />

printing routines. Pages whose content is generated entirely by <strong>JavaScript</strong><br />

print only in NN3+ and IE4+.<br />

prompt(“message”, “defaultReply”)<br />

windowObject.prompt()<br />

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

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

The function that receives values from the prompt dialog box in Listing 16-29<br />

(see the dialog box in Figure 2-8) does some data-entry validation (but certainly not<br />

enough for a commercial site). The function first checks to make sure that the<br />

returned value is neither null (Cancel) nor an empty string (the user clicked OK<br />

without entering any values). See Chapter 43 of the <strong>JavaScript</strong> <strong>Bible</strong> for more about<br />

data-entry validation.<br />

Listing 16-29: The Prompt Dialog Box<br />

<br />

<br />

window.prompt() Method<br />

<br />

function populateTable() {<br />

var howMany = prompt(“Fill in table for how many factors?”,””)<br />

if (howMany != null && howMany != “”) {

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

Saved successfully!

Ooh no, something went wrong!