Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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()
    {
    	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
    Last edited by jimmycook; 10-15-2008 at 03:34 PM. Reason: mistake

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Hi jimmycook,
    Please edit your post to wrap your codes by [code][/code], so that it'd be easy to read.

    PS: welcome to CF.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm not too sure what you mean. Im new to this.

    Sorry

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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()
    {
    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>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    jimmycook (10-15-2008)

  • #5
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for that

    Any developments so far...

    thanks

  • #6
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    •