• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. HTML Forms > Setting Focus in a Form

Setting Focus in a Form

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.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint