asp.net.ph

Skip Navigation Links

setExpression Method

DHTML Methods


DOM Level 2 Specification.

Sets the CSS property:value expression ( a declaration block ) for a given object.

Syntax

HTML <ELEMENT STYLE="sAttributeName:expression ( sExpression ) ">
Scripting object.setExpression ( sPropertyName, sExpression2, sLanguage )

Parameters

sAttributeName Required. Name of the attribute to which sExpression will be added.
sPropertyName Required. Name of the property to which sExpression will be added.
sExpression Required. Any legal JScript™ ( compatible with ECMA-262 language specification ) statement without quotations or semicolons. This string may include references to other properties on the current page. Array references are not allowed on object properties included in this script.
sExpression2 Required. Any legal script. This string may include references to other properties on the current page. Array references are not allowed on object properties included in this script.
sLanguage Required. This can be one of the following values:

JScript Specifies the language as JScript.
VBScript Specifies the language as VBScript.
JavaScript Specifies the language as JavaScript.


Return Value

No return value.

Remarks

Thie method is used to set a CSS style expression for an object. This method is Microsoft's® implementation of the generic setProperty interface provided for in the DOM.

The cssText property is a unique property that is not compatible with the dynamic properties implementation. Authors should not use cssText with any dynamic property methods.

The setExpression method applies to the style subobject and can be used to add expressions to supported CSS Attributes. This method is also available in scripting for the innerHTML and value attributes of objects. Only the removeExpression method can clear values set using setExpression.

Using setExpression on an object in script:

object.setExpression ( sProperty, sExpression, 
   sLanguage ) 

Using setExpression on the style subobject:

object.style.setExpression ( sProperty,  
   sExpression,  sLanguage ) 

Example

The following sample code fragments illustrate the implementation of setExpression in both HTML and scripting. In each sample, the width of the blue box is equal to the sum of the values of the first two text boxes. When a value in one of the text boxes is changed, the width of the blue box is recalculated.

The following sample code illustrates the HTML implementation of setExpression.

<input size=4 id="Box1" value=40> 
<input size=4 id="Box2" value=40>
<p></p>
<input type=text id="Box3" 
  style="width:expression ( eval ( Box1.value ) + 
  eval ( Box2.value ) );background:gold">

 Show me 

The same functionality can be implemented in client-side script as shown in the following code:

<input onkeypress="numOnly ( )" size=4 id="Box1"
  value=40>
<input onkeypress="numOnly ( )" size=4 id="Box2"
  value=40>
<p></p>
<input type=text id="Box3"
  style="background:silver"></div>

<script language="JavaScript">
<!--
Box3.style.setExpression ( 
  "width", "eval ( Box2.value ) +eval ( Box1.value )", 
  "javascript" );
//—>
</script>

 Show me 

See Also

Dynamic Properties, getExpression, recalc, removeExpression



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note