c-- styles for logos and headline links do not modify internet, red, or black styles -->
|
|
|
|
|
|
|
|
Putting JavaScript to
Work If you look at the first line
of function compute(), you will notice that we assign
the flag Next you will notice an if statement. This is used for the array
of choice for the first component. Recall that in JavaScript, the first
element of an array is defined as the 0th (not the 1st!) element. So
the array for the first selection option looks like this: Back to our if statement. Notice carefully how we called our
first option from processor inside the if statement. Remember that we
did not name the form anything in HTML. So all we needed to do is call
the array element of the object, its property and we got the object
(in our case a form). In the if statement, if the user chooses the first option from processor,
we assign pr_flag=0 and pr_print="None [$0]". The reason we assign pr_flag=0,
as in other selection options as well, is because Select has a value
of 0. Naturally, if the user presses the button named price before choosing
any of the options from any of the selection options, you are bound
to get a zero for your price. When that happens, if the user presses
the button Print Preview you will see that for all the components there
will be None [$0] next to them. As you can see, we used else if statements in processor to assign the
appropriate price for each option to pr_flag ($540, $40, $680 and $421).
We also assigned the appropriate component choice for each selection
in pr_print for the print preview window. The next selection option is speed. Like before, we used if and else
if statements to find out if the user has selected one the elements
of this object. After we are done with all the selection options we now need to add
all flags. For this we use the variable T_Price. This simple
addition method is shown below: Finally we need to display the value of T_Price in our text box. To
do that we need to replace the blank property of the text box, value
with T_Price. So, we do the following: This function will create a window with the listing of all the choices
chosen by the user as well as the computed price. Here is the listing: In this function, first we made sure that the compute() function is
called. Next we had a variable text which carried all the information
necessary to create a new page. For example, we defined the BGCOLOR
of the document, as we would do to make a new HTML page. After our page is made we used the window object to create a new window.
Notice the properties that were used in our new window. Finally, we use the document property write to display the text.
Voila! The complete JS/Configurator
is online for you to experiment with, download and customize for your
own pages.
|
Some Other JavaScript Sources On IDM
·
JavaScript FAQ |