Specifications

Objects 59
Example
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 functions objectTag() and insertObject() are mutually exclusive; if both are defined in a
document, then
objectTag() is used. See the insertObject() function for more information.
Inserts a string of code into the users document. In Dreamweaver 4, if the focus was in Code view
and the selection was a range (meaning not an insertion point), the range was replaced by the
string that
objectTag() returns. This is true, even if objectTag() returned an empty string or
returned nothing. Because the main reason for returning an empty string, or
null, from
objectTag() was because edits to the document have already been made manually, having the
selection be replaced by "" often deleted the edit. In Dreamweaver MX, returning an empty
string, or
null (also known as "Return;"), is a signal to Dreamweaver to do nothing.
Note: The assumption is that edits have been made manually prior to the return statement, so doing nothing in
this case is
not equivalent to clicking Cancel.
Arguments
None.
Returns
Dreamweaver expects the string to be inserted in the users document.
Example
The following instance of objectTag() inserts an OBJECT/EMBED combination for a specific
ActiveX control and plug-in:
function objectTag() {
return ’\n’ +
'<OBJECT CLASSID="clsid:166F1OOB-3A9R-11FB-8075444553540000" \n'¬
+ 'CODEBASE="http://www.mysite.com/product/cabs/¬
myproduct.cab#version=1,0,0,0" \n' + 'NAME="MyProductName"> \n' ¬
+ '<PARAM NAME="SRC" VALUE=""> \n' + '<EMBED SRC="" HEIGHT="" ¬
WIDTH="" NAME="MyProductName"> \n' + '</OBJECT>'
}