LED METER FUNCTIONALITY

The purpose of this exercise is to proportionately change the height property of an image proportionate to the user-selected value chosen in the form menu.

Components:

Construction:

  1. Design Graphic Level Meter
  2. Develop a form list with values 0-20
  3. Attach an onChange event handler to run a JavaScript function
  4. Allow JavaScript function to change CSS style rules either on the image or the box that contains the image
  5. Define CSS styles to position the image absolutely within the box that contains the image and to the bottom (this resolves an issue where the image opens downward rather than upward)

Factors: body css javascript

Value

Type

Location

Relationship

attack

[name][id]

body

led_meter

led_meter

[image]

body

adjustMeter() function

ledbox

[id]

body

#ledbox

adjustMeter()

JavaScript function

head

Attack, led_meter

Method:

  1. Select a value inside the form list box
  2. The Led Bar increases or decreases its height proportionate to the value chosen.

Process:

  1. User clicks on form input
  2. onChange event handler passes the value of the selection as a parameter to a JavaScript function
  3. The function uses the form's value to change the style property of the image's parent element.
  4. The image reflects the change in its height.

Formula:

element.style.height=(obj.value*2)+'px'

The image in this example is 40 pixels high

The value range in the form list is between 0-20

The factor of multiplication is determined by the formula x(pixels high) divided by 20(value range)