Click to return to the DHTML, HTML     
queryCommandValue Method     refresh Method     DHTML Methods    
Web Workshop  |  DHTML, HTML & CSS

recalc Method


Recalculates all dynamic properties in the current document.

Syntax

document.recalc([bForceAll])

Parameters

bForceAll Optional. Boolean that specifies one of the following values:
falseDefault. Recalculates only those expressions that have changed since the last recalculation.
trueRecalculates all expressions in the document.

Return Value

No return value.

Remarks

Implicit dependencies, internal property changes, and related properties can cause some expressions not to recalculate, even though the properties being referenced might have changed. For example, resizing the main window changes document.body.clientWidth. Expressions that reference clientWidth might not be recalculated, because the change might not be recognized.

Implicit dependencies refer to properties that can be altered by changes in other properties. For example, the height of a DIV implicitly depends on the innerHTML of the DIV. However, if an expression references the height, a change in the innerHTML, which might alter the height, does not cause a recalculation of the expression on a subsequent call to recalc.

Related properties can access or manipulate data or behaviors through one or more other properties. For example, pixelLeft and posLeft can set or retrieve the left position of the element. However, if an expression that references element.pixelLeft and element.posLeft is altered, the expression might not be recalculated on subsequent calls to recalc.

Related properties that can cause this behavior include the following: clientHeight, clientLeft, clientTop, clientWidth, height, left, offsetHeight, offsetLeft, offsetTop, offsetWidth, pixelHeight, pixelLeft, pixelTop, pixelWidth, posHeight, posLeft, posTop, posWidth, and top.

To force recalculations of all expressions, you should refer to the same property name or manually call recalc(true).

Example

The following examples use the recalc method in HTML and script to change the width of an element by the value specified in a text field.

Sample Code

This example shows the HTML implementation of recalc.

<INPUT TYPE=text ID=oBox1 value=40>The sum of the values in 
    these two text boxes determines the width
<BR><INPUT TYPE=text ID=oBox2 value=40>of the blue text 
    box below.
<BR><INPUT TYPE=text ID=oBox3 
    STYLE="width:expression(eval(oBox1.value) + 
    eval(oBox2.value)); background-color:blue">
<BR><INPUT TYPE=button ID=Button 
    value="Click to resize blue box above" onclick="recalc()">

This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

This example shows how the same functionality in the preceding example can be implemented in script using recalc.

<INPUT TYPE=text ID=oBox1 value=40>The sum of the values in 
    these two text boxes determines the 
<BR><INPUT TYPE=text ID=oBox2 value=40>width of the 
    blue text box below.
<BR><INPUT TYPE=text ID=oBox3 STYLE="background-color:blue">
<BR><INPUT TYPE=button ID=Button 
    value="Click to resize blue box above" onclick="update()">

<SCRIPT>
oBox3.style.setExpression("width","eval(oBox1.value) + 
    eval(oBox2.value)","jscript");
function update()
{
    document.recalc();
}
</SCRIPT>
This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

This example uses recalc to define a style that positions the DIV at 200px, 200px in Internet Explorer 4.0, and animates it over time in Internet Explorer 5.

<DIV STYLE="position: absolute; top: 200px; left: 200px; 
    left: function(time.ms / 100);" />
This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
document

See Also

Dynamic Properties, getExpression, removeExpression, setExpression



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.