...

View Full Version : Defining an array in a equation



jimmycook
10-15-2008, 02:51 PM
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].


<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()
{
if(confirm("Are you sure you wish to purchase this?"))
document.form1.submit()
}

</script>
</head>
<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>
<P><B>Your Quotation:</B></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

abduraooft
10-15-2008, 03:04 PM
Hi jimmycook,
Please edit your post to wrap your codes by
][/COLOR], so that it'd be easy to read.

PS: welcome to CF.

jimmycook
10-15-2008, 03:18 PM
I'm not too sure what you mean. Im new to this.

Sorry

abduraooft
10-15-2008, 03:22 PM
When you wrap your code before posting here by the above specified tag, it'll become

<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()
{
if(confirm("Are you sure you wish to purchase this?"))
document.form1.submit()
}

</script>
</head>
<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>
<P><B>Your Quotation:</B></P>
<Input type = "text" NAME = "quote" SIZE = 10>
<P><Input Type = "button" Name ="done" Value = "Purchase"
onClick = "confirmPurchase()">
</P></form>
</body>

</html>

jimmycook
10-15-2008, 03:43 PM
thanks for that

Any developments so far...

thanks

vendettamedia
10-15-2008, 07:32 PM
You need to define your value in this string.



howmuch= eval("document.form1.InsVal.value")


when you pass your howmuch variable you are passing a null value or 0
so when you try:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum