Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms in Javascript 4.7

Status
Not open for further replies.

tempoman

Programmer
May 9, 2000
41
0
0
AU
I am trying to add the total for some drop down list but am having trouble referencing the value, I just keep on getting a value. The code however works perfectly in IE and Netscape 6.

Here is my code:

<javascript>
function PriceUpdate(whichbox) {

with (whichbox.form) {

alert(whichbox.value);//this gives me null all the time
if (whichbox.selected == false)
hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value);
else
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value);
return(formatCurrency(hiddentotal.value));
}
}
</javascript>

<select name=&quot;Acc&quot; size=&quot;1&quot; onChange=&quot;this.form.total.value=PriceUpdate(this);&quot;>
<option VALUE=&quot;&quot;>Not Required</option>
<option value=&quot;135.00&quot;>Protein Structure Analysis </option>
<option value=&quot;320.00&quot;>FULL Registration</option>
</script>

Come someone please help me.

Thanx

Richard
 
I can't tell for sure, but you are sending this.form.total.value to the function and your SELECT is named &quot;Acc&quot; -- so maybe you should call

onChange=&quot;PriceUpdate(this);&quot;

and that's it. If you can't ever get whichbox.value to popup a value then you must not be passing the right thing.

You also have some interesting tags... how about this instead:

<script language=&quot;JavaScript&quot;>
function PriceUpdate(whichbox) {
alert(whichbox.value); // for testing
var hiddentotal = 50;
var newHiddenTotal = 0;
if (whichbox.value == &quot;&quot;)
newHiddenTotal = eval(hiddentotal);
else
newHiddenTotal = eval(hiddentotal) + eval(whichbox.value);
alert(newHiddenTotal);
}

</script>

<select name=&quot;Acc&quot; size=&quot;1&quot; onChange=&quot;return PriceUpdate(this);&quot;>
<option VALUE=&quot;&quot;>Not Required</option>
<option value=&quot;135&quot;>Protein Structure Analysis </option>
<option value=&quot;320&quot;>FULL Registration</option>
</select>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top