Part 4: Balancing Braces
Whenever you want to be sure that you have a closing brace for every opening brace, use Dreamweaver's Balance Braces tool. Here's how it works:
Click anywhere on line 32 in Dreamweaver's Code view of your "contact us" form. Click Edit, Balance Braces. Dreamweaver finds the closest opening brace and then its closing brace "partner," and it highlight all the code in between, as shown in Figure 18.
Figure 18 Edit, Balance Braces highlights the code between the two pairs of braces.
The Balance Braces feature works with curly braces, parentheses, and brackets.
So now let's see how Dreamweaver handles the missing brace problem. In Dreamweaver's Code view, click anywhere on lines 26 or 27. Click Edit, Balance Braces.
The Balance Braces features correctly found the closest opening brace, located on line 25, but did not find its closing partner. So, it highlighted all the code through the last closing curly brace on line 60. As the programmer writing this code, you'll know that the if statement beginning on line 25 is only a few lines long, so you can then confirm that the closing curly brace is missing and insert it.
The next time you encounter problems in your JavaScript code, remember to use Dreamweaver's JavaScript Debugger and Balance Braces tools to debug your code. It can save you time and headaches.