Graphics Programs Reference
In-Depth Information
12. Save the page, and then toggle on Live View . You will test the behavior.
13. Enter data in the form, typing the word potato in the email_address field, and
then click the Submit button. A dialog box opens, stating that the email_address
field must contain an e-mail address. See Figure 7-5.
Figure 7-5
Live View Alert dialog box
14. Click the OK button, toggle off Live View to return to Design view, and then close
the page.
Adding a Custom Script to a Page
You can add the advanced functionality of behaviors to a Web page by writing your own
code (usually JavaScript) in the Script dialog box or in the Document window in Code
view. Code you write is not actually considered a behavior because it is not added to the
reusable prewritten choice lists in the Behaviors panel. Instead, code you write is consid-
ered a custom script and will usually appear in the Behaviors panel when you select the
object to which it is attached.
Current best practices for adding custom scripts suggest that you write the script in a
separate page, include that page in the local root folder, and then insert code into the
page that loads the script when the page is loaded. This method is preferred because
scripts are often used in more than one page of a site and this keeps the code lean and
clean. Also, as with styles, when you link a script to various pages, you can update all
those pages at once by editing the single script. To keep your site organized, you create a
scripts folder in which to store all the scripts in the site.
Writing Custom JavaScripts
If you know JavaScript, you can write your own scripts. You can also find scripts that
other people have written and posted for public use. However, you'll often need to
fine-tune scripts that you use in Web pages, so it is a good idea to learn at least enough
JavaScript so that you can debug a page. Some good basic JavaScript resources include:
webreference.com/programming/javascript
javascript.com
javascript.internet.com
You will add a custom script written in JavaScript by another programmer to the home
page. The script randomly selects one of the included quotations to appear in the page
when the page is loaded in a browser window, providing the illusion that the page has
a continuous source of fresh content. The script adds a CSS class style named “quote” to
the displayed quotation. You will create a quote class style, and add it to the style sheet
so you can customize and change the look of the quotations in the page.
Search WWH ::




Custom Search