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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cost Calculator Help!

    I want the calculator to take what was clicked display the item number and also the cost. (if possible i'd like to be able to display cost with no button) sorry if the code is messy i'm new to javascript.

    Code:
    <SCRIPT TYPE="TEXT/JAVASCRIPT">
    // Definitions
    var in2 = ""
    var in3 = ""
    //costs
    var $mat = ""
    var cmat = Number($mat)
    var $sqft = ""
    var csf = Number($sqft)
    var chngcost = cmat*csf
    var $coga = 30
    var $cos = 40
    var $coshp = 15
    var $total = chngcost + $coga + $cos + $coshp
    // Add a letter to string
    function itemnumber2(numb) {
      in2 = numb
      document.myform.i2.value = in2
      document.itemnumber.i2.value = in2
      if (in2 == "10") {
    $mat = 3
    document.myform.cmat1.value = $mat
    }
    if (in2 == "11") {
    $mat = 6
    document.myform.cmat1.value = $mat
    }
    if (in2 == "12") {
    $mat = 12
    document.myform.cmat1.value = $mat
    }
    }
    function itemnumber3(numb) {
      in3 = numb
      document.myform.i3.value = in3
      document.itemnumber.i3.value = in3
      if (in3 == "1") {
    $sqft = 7.5
    document.myform.sqrf1.value = $sqft
    }
    if (in3 == "2") {
    $sqft = 5.5
    document.myform.sqrf1.value = $sqft
    }
    if (in3 == "3") {
    $sqft = 5
    document.myform.sqrf1.value = $sqft
    }
    }
    //total cost function
    function totalcost() {
      ttc1 = $total
      document.myform.ttc.value = ttc1
    }
    </SCRIPT>
    Code:
    <input type="radio" id="10" name="Size" value="18x22" onclick="itemnumber2(10)"> 18" X 22"<br>
    <input type="radio" id="11" name="Size" value="24x36" onclick="itemnumber2(11)"> 24" X 36"<br>
    <input type="radio" id="12" name="Size" value="36x48" onclick="itemnumber2(12)"> 36" X 48"<br>
    Code:
    <input type="radio" id="1" name="Material" value="Photo Gloss" onclick="itemnumber3(1)"> Photo Gloss<br>
    <input type="radio" id="2" name="Material" value="Bond Laminate" onclick="itemnumber3(2)"> Bond Laminate<br>
    <input type="radio" id="3" name="Material" value="Photo Gloss" onclick="itemnumber3(3)"> Vinyl<br>
    Code:
    <form name="itemnumber" action="#">
    <span class="style6">Item # <input type="text" size="3" name="i1" value="101" disabled>-
    <input type="text" size="2" name="i2" disabled>-<input type="text" size="1" name="i3" disabled></span></p>
    </form>
    Code:
    <input name="cost" type="button" onclick="totalcost()" value="Cost"> 
    $<input type="text" size="5" name="ttc" disabled>
    Last edited by Trnxrdm; 04-04-2011 at 05:11 PM.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    The very first problem that sticks out with your code is incorrect comparison operators

  • #3
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thnx that helped but i still cant get them to multiply and then add up with the other costs for a total...


  •  

    Posting Permissions

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