Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: making a calculator

  1. #11
    Join Date
    Jun 2005
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thx both of u, really appreciating this, thx again

  2. #12
    Join Date
    Jun 2005
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    oh n sory 1 last request in urs mwinter :P

    can you put the price before tax and after tax to show, jsut like tweys? thanks man

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <form action="">
      <label>Item price: <input type="text" name="price"></label>
      <label>Shipping charge: <input type="text" name="shipping"></label>
      <label>Subtotal: <input type="text" name="subtotal"></label>
      <label>Tax group:
      <select name="tax" size="1">
        <!-- VAT:  <option value="0.175">...</option> -->
      </select></label>
      <label>Total: <input type="text" name="total"></label>
      <input type="button" value="Calculate" onclick="calculate(this.form);">
    </form>
    Code:
    function calculate(f) {
      var e = f.elements,
          p = e.price.value,
          s = e.shipping.value,
          t = e.tax,
          m = ['The following fields are invalid:\n'];
    
      if(!Number.isReal(p)) {m.push('Item price');}
      if(!Number.isReal(s)) {m.push('Shipping charge');}
      if(-1 == t.selectedIndex) {m.push('Tax group');}
      if(1 != m.length) {
        alert(m.join('\n'));
        return false;
      }
      e.total.value = ((+p + (+s)) * (1 + (+t.options[t.selectedIndex].value))
                                   * 100).toCurrency('$');
      e.subtotal.value = (+p + (+s)).toCurrency('$');
    }
    
    if('function' != typeof Array.prototype.push) {
      Array.prototype.push = function(v) {
        var i = this.length >>> 0,
            j = 0,
            n = arguments.length;
    
        while(n > j) {this[i++] = arguments[j++];}
        return (this.length = i);
      };
    }
    Number.prototype.toCurrency = function(c, t, d) {
      var n = +this,
          s = (0 > n) ? '-' : '',
          m = String(Math.round(Math.abs(n))),
          i = '',
          j, f;
          c = c || '';
          t = t || '';
          d = d || '.';
    
      while (m.length < 3) {m = '0' + m;}
      f = m.substring((j = m.length - 2));
      while (j > 3) {i = t + m.substring(j - 3, j) + i; j -= 3;}
      i = m.substring(0, j) + i;
      return s + c + i + d + f;
    };
    Number.isReal = function(s) {
      return /^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?$/.test(s);
    };
    Haven't got a clue what the difference between (s) and (+s) is, I just included it because Mike did
    Last edited by Twey; 08-02-2005 at 03:04 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Jun 2005
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thx bro

  5. #15
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help

    Im setting up a website that needs to have a calculator similiar to this link:
    https://www.101incorporate.com/incorporation-order.htm

    The user need to be able to click on things and the calculator need to change according to the different packages and items they select. And the calculator will total it out.

    Can anyone help me? Please. Thanks!

  6. #16
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Perhaps DD can help move this post. But this question really belongs in the requesting script thread

    I know this can be done in PHP and JS, it just depends on what you want/need/are able to use
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

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