SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Stafford, Virginia, USA
    0 Post(s)
    0 Thread(s)

    Calculate a Dollar Value From a Drop Down List.

    Let me start by saying my JavaScript is limited to cut and paste.

    I'm trying to get a calculator made up that will calculate the cost of a service call and labour.

    Stage one is the service call.

    If you check this link, this is basically the first step:

    I want a different dollar value associated with each zip code, so that there will be a box after "Service Call $" displaying the associated fee. There are going to be 5 different fees for this range of zip codes. $35, $40, $45, $50, and $55. The "other" box will give the fee with a message that a representative will need to call to discuss the job.

    But anyway,

    There will be a display box under that which will always be $15 more than the service call for the associated zip code.

    Under that will be the Total Price.

    I will be adding more check boxes for different labour to be done, but I'm doing one step at a time so I can understand this script and not have a clip and pasted mess I can't decipher.

    Help me please with stage one. Associate a dollar amount to each zip code.

  2. #2
    SitePoint Addict
    Join Date
    Jul 2000
    0 Post(s)
    0 Thread(s)
    This should get you started:
    HTML Code:
    <script language="JavaScript">
    var aRates = new Array();
    aRates[20108] = 35;
    aRates[20110] = 40;
    aRates[20111] = 45;
    aRates[20112] = 50;
    aRates[20113] = 55;
    function SetRate(zipchosen){
      document.form1.rate.value = aRates[zipchosen];
    <form name="form1">
    Please select your Zip Code:
    <select name="zipcode" size="1" onChange="SetRate(document.form1.zipcode.value)">
    <option value="zero">Please select your Zip Code</option>
    <option value="20108">20108 Manassas, Manassas City</option>
    <option value="20110">20110 Manassas, Manassas City</option>
    <option value="20111">20111 Manassas, Prince William County</option>
    <option value="20112">20112 Manassas, Prince William County</option>
    <option value="20113">20113 Manassas, Manassas Park City</option>
    <option value="20119">20119 Catlett, Fauquier County</option>
    <option value="20136">20136 Bristow, Prince William County</option>
    <option value="20138">20138 Calverton, Fauquier County</option>
    <option value="20139">20139 Casanova, Fauquier County</option>
    <option value="20181">20181 Nokesville, Prince William County</option>
    <option value="20182">20182 Nokesville, Prince William County</option>
    <option value="20187">20187 Warrenton, Fauquier County</option>
    <option value="22026">22026 Dumfries, Prince William County</option>
    <option value="22125">22125 Occoquan, Prince William County</option>
    <option value="22134">22134 Quantico, Prince William County</option>
    <option value="22135">22135 Quantico, Stafford County</option>
    <option value="22172">22172 Triangle, Prince William County</option>
    <option value="22191">22191 Woodbridge, Prince William County</option>
    <option value="22192">22192 Woodbridge, Prince William County</option>
    <option value="22193">22193 Woodbridge, Prince William County</option>
    <option value="22194">22194 Woodbridge, Prince William County</option>
    <option value="22195">22195 Woodbridge, Prince William County</option>
    <option value="22401">22401 Fredericksburg, Fredericksburg City</option>
    <option value="22402">22402 Fredericksburg, Fredericksburg City</option>
    <option value="22403">22403 Fredericksburg, Stafford County</option>
    <option value="22404">22404 Fredericksburg, Fredericksburg City</option>
    <option value="22405">22405 Fredericksburg, Stafford County</option>
    <option value="22406">22406 Fredericksburg, Stafford County</option>
    <option value="22407">22407 Fredericksburg, Spotsylvania County</option>
    <option value="22412">22412 Fredericksburg, Stafford County</option>
    <option value="22430">22430 Brooke, Stafford County</option>
    <option value="22463">22463 Garrisonville, Stafford County</option>
    <option value="22471">22471 Hartwood, Stafford County</option>
    <option value="22508">22508 Locust Grove, Orange County</option>
    <option value="22545">22545 Ruby, Stafford County</option>
    <option value="22554">22554 Stafford, Stafford County</option>
    <option value="22555">22555 Stafford, Stafford County</option>
    <option value="22556">22556 Stafford, Stafford County</option>
    <option value="22712">22712 Bealeton, Fauquier County</option>
    <option value="22718">22718 Elkwood, Culpeper County</option>
    <option value="22720">22720 Goldvein, Fauquier County</option>
    <option value="22726">22726 Lignum, Culpeper County</option>
    <option value="22728">22728 Midland, Fauquier County</option>
    <option value="22734">22734 Remington, Fauquier County</option>
    <option value="22736">22736 Richardsville, Culpeper County</option>
    <option value="22739">22739 Somerville, Fauquier County</option>
    <option value="22741">22741 Stevensburg, Culpeper County</option>
    <option value="22742">22742 Sumerduck, Fauquier County</option>
    <option value="other">Not Sure - Not Listed Here</option>
    Service Call $ <input type="text" name="rate">
    Minimum Charge $ <input type="text" name="minimum">
    Total $
    You'll need to add a line for each zip code for the aRates array


Posting Permissions

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