Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Defining an array in a equation

1. ## Defining an array in a equation

I have a problem with some course work, I am struggling to define my rates (lines 3-6) to the Ski region options. And then into the sum where at the moment it has rate[0].
Code:
```<script language="javascript">
var rate = new Array();
rate[0] = 8;
rate[1] = 4;
rate[2] = 6;
rate[3] = 12;

function calculate()
{
howmuch= eval("document.form1.InsVal.value")
for(loop = 0; loop <3; loop++)
if (document.form1.cover[loop].checked)
level = loop+1

cost = eval(10 + howmuch/100*rate[0]*level)
document.form1.quote.value = cost
}
function confirmPurchase()
{
document.form1.submit()
}

</script>
<body>
<H1 Align=CENTER>James Cook</H1>
<H2 Align=Center>Ski Boots Insurance Specialists</H2>

<Form name = form1 Method = post
Action="mailto:F07387815@tic.ac.uk">

<P><B> Value of ski boots:</B></P>
<p>
<input type = text NAME = InsVal SIZE = 10>
<P>
</p>
<p>
<b>Ski Region</b></p>

<select size="1" name="D1">
<Option = 1> Massif
<Option = 2> Grand Massif
<Option = 3> Mont Blanc
<Option = 4> Courchevel

</Option>
</select>
<br>
</p>
<p><B>Insurance Type:</B></p>
<p>
<input type = Radio NAME = cover>
Third Party <br>
<input type = Radio NAME = cover>
Third Party Fire and Theft <br>
<input type = Radio NAME = cover CHECKED>
Comprehensive </p>
<P><Input type = "button" Name = "calc" Value = "Get quote"
onClick = "calculate()"></P>
<Input type = "text" NAME  = "quote" SIZE = 10>
<P><Input Type = "button" Name ="done" Value = "Purchase"
onClick = "confirmPurchase()">
</P></form>
</body>

</html>```
If anyone can help it would be very helpful.

Thanks

James

• Hi jimmycook,

PS: welcome to CF.

• I'm not too sure what you mean. Im new to this.

Sorry

• When you wrap your code before posting here by the above specified tag, it'll become
Code:
```<script language="javascript">
var rate = new Array();
rate[0] = 8;
rate[1] = 4;
rate[2] = 6;
rate[3] = 12;

function calculate()
{
howmuch= eval("document.form1.InsVal.value")
for(loop = 0; loop <3; loop++)
if (document.form1.cover[loop].checked)
level = loop+1

cost = eval(10 + howmuch/100*rate[0]*level)
document.form1.quote.value = cost
}
function confirmPurchase()
{
document.form1.submit()
}

</script>
<body>
<H1 Align=CENTER>James Cook</H1>
<H2 Align=Center>Ski Boots Insurance Specialists</H2>

<Form name = form1 Method = post
Action="mailto:F07387815@tic.ac.uk">

<P><B> Value of ski boots:</B></P>
<p>
<input type = text NAME = InsVal SIZE = 10>
<P>
</p>
<p>
<b>Ski Region</b></p>

<select size="1" name="D1">
<Option = 1> Massif
<Option = 2> Grand Massif
<Option = 3> Mont Blanc
<Option = 4> Courchevel

</Option>
</select>
<br>
</p>
<p><B>Insurance Type:</B></p>
<p>
<input type = Radio NAME = cover>
Third Party <br>
<input type = Radio NAME = cover>
Third Party Fire and Theft <br>
<input type = Radio NAME = cover CHECKED>
Comprehensive </p>
<P><Input type = "button" Name = "calc" Value = "Get quote"
onClick = "calculate()"></P>
<Input type = "text" NAME = "quote" SIZE = 10>
<P><Input Type = "button" Name ="done" Value = "Purchase"
onClick = "confirmPurchase()">
</P></form>
</body>

</html>```

• ## Users who have thanked abduraooft for this post:

jimmycook (10-15-2008)

• thanks for that

Any developments so far...

thanks

• You need to define your value in this string.

Code:
`howmuch= eval("document.form1.InsVal.value")`
when you pass your howmuch variable you are passing a null value or 0
so when you try:
Code:
`cost = eval(10 + howmuch/100*rate[0]*level)`
you are basically passing 0 or null to be divided by 100. Thats why your code is blowing up.

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•