Setting Focus in a Form

Team-Fly    

Macromedia® DreamWeaver® MX Unleashed
By Matthew Pizzi, Zak Ruvalcaba
Table of Contents
Chapter 6.  HTML Forms


In the Dreamweaver classes that I teach, students often ask how they can get a blinking cursor to appear automatically in the form. You have to use JavaScript, but the process is a simple one. Suppose you wanted a blinking cursor to appear in the first text field of the form_design.html. The important thing is to know the name of the text field and to know the name of the form. Highlight each of them to get their names in the Properties Inspector. To set the focus, follow these steps:

  1. You need to write a JavaScript that looks like this: window.document. formname.fieldname.focus(). In the next step, you'll do just that. You'll place the script in the proper location within the HTML and swap the form name and field name attributes with the actual names found within this form.

  2. Click in the code and design view to view both the code source and the design, as shown in Figure 6.25. In the body tag, after the background attribute, type in the JavaScript after an onload command. When all is said and done the <body> tag should look like this:

     <body bgcolor="#666666" onload="window.document.questions.name.focus()">  
  3. Preview your page in a Web browser and notice that a blinking cursor is in the first text field.

You can download a completed version of this file located on the companion Web site, http://www.dreamweavermxunleashed.com.


    Team-Fly    
    Top


    Macromedia Dreamweaver MX Unleashed
    Macromedia Dreamweaver MX 2004 Unleashed
    ISBN: 0672326310
    EAN: 2147483647
    Year: 2002
    Pages: 321

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net