User Guide
124 Chapter 6: Insert Bar Objects
Returns
Dreamweaver expects a string that contains an error message or an empty string. If it returns an
empty string, the Object dialog box closes when the user clicks OK. If it is not empty,
Dreamweaver displays the error message and the dialog box remains.
Enabler
canInsertObject()
Example
The following example uses the insertObject() function because it needs to validate input
before inserting code:
function insertObject() {
var theForm = document.forms[0];
var nameVal = theForm.firstField.value;
var passwordVal = theForm.secondField.value;
var errMsg = "",
var isValid = true;
// ensure that field values are complete and valid
if (nameVal == "" || passwordVal == "") {
errMsg = "Complete all values or click Cancel."
} else if (nameVal.length < 4 || passwordVal.length < 6) {
errMsg = "Your name must be at least four characters, and your password at
least six";
}
if (!errMsg) {
// do some document manipulation here. Exercise left to the reader
}
return errMsg;
}
objectTag()
Description
The objectTag() and insertObject() functions are mutually exclusive: If both are defined in a
document, the
objectTag() function is used. For more information, see “insertObject()”
on page 123.
This function inserts a string of code into the user’s document. In Dreamweaver MX, returning
an empty string, or a null value (also known as "return;"), is a signal to Dreamweaver to
do nothing.
Note: The assumption is that edits have been made manually before the return statement, so doing
nothing in this case is not equivalent to clicking Cancel.
In Dreamweaver 4, if the focus is in Code view and the selection is a range (meaning that it is not
an insertion point), the range is replaced by the string that the
objectTag() function returns.
This is the value true, even if the objectTag() function returns an empty string or returns
nothing. The reason for returning an empty string, or a
null value from the objectTag()
function is because edits to the document have already been made manually. Otherwise, double
quotes ("") often deletes the edit by replacing the selection.