View Full Version : Correct usage of 'else'?

07-22-2002, 10:05 PM
I'm trying to write a simple script (I hope its simple):[list=1]
If the value of the select box is 1001, then I want to assign the variable TEST1 a value of 50
If the value is not 1001 then I would like TEST1 to equal 0.
The same goes for TEST2
The problem I am having TEST1 is ALWAYS 50 and TEST2 is ALWAYS 70, so I have a sneaking suspicion that I am misusing else, or just leaving something out.

function ComputeTotal(form)

if (document.form.test.value = 1001)
TEST1 = 50
TEST1 = 0

if (document.form.test.value = 1002)
TEST2 = 70
TEST2 = 0

subtotal = (TEST2 + TEST1)

document.form.total.value = subtotal

Eventually there will be more than 2 options per select box and I need the value to be an inventory number instead of just the mere price.

Also while I'm here, I have another question: Would it be possible to have a non numerical value for the options in select box "test" and if so, how would I define them? (I tried making the values "testa" and "testb" but it kept coming back saying that "testa is undefined")

Forgive me for my "noobness".

07-22-2002, 10:14 PM
else if fine it's your test.

you were assigning the value versus testing it. Change from single = to a double =

if (document.form.test.value == 1001)

07-22-2002, 10:29 PM
I knew it was something simple, that's what I get for refusing to take any type of computer class.

07-23-2002, 07:53 AM
Being the doof that I am, I realized after typing about 15 if (blah blah blah)s, that an array would work perfectly. So for future reference this is an example of how I accomplished it:

var TESTvalue = new Array()
TESTvalue[0] = 50
TESTvalue[1] = 70

var TEST1value = new Array()
TEST1value[0] = 500
TEST1value[1] = 700

function ComputeTotal()
TEST = TESTvalue[form.test.selectedIndex]
TEST1 = TEST1value[form.test1.selectedIndex]

total = (TEST + TEST1)

form.total.value = total
<BODY onLoad="ComputeTotal()">

<form name="form">
<select name="test" size="1" onChange="ComputeTotal()">
<option value="whatever">$50</option>
<option value="whatever">$70</option>
<select name="test1" size="1" onChange="ComputeTotal()">
<option value="whatever">$500</option>
<option value="whatever">$700</option>
<input type="text" name="total">

oopsie, typo :o

Mrs G
07-27-2002, 12:58 AM
If you find your script not working try adding " at the end of ComputeTotal() at lines

<select name="test" size="1" onChange="ComputeTotal()>


<select name="test1" size="1" onChange="ComputeTotal()>

like so

<select name="test" size="1" onChange="ComputeTotal()">
<select name="test1" size="1" onChange="ComputeTotal()">

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum