www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Help with web form and calculating costs

Hybrid View

  1. #1
    Join Date
    Sep 2013
    Posts
    8

    resolved [RESOLVED] Help with web form and calculating costs

    I have been updating a web payment form and have run into some trouble.

    The original form is here if you want to look at it - http://mk18.web44.net/#order

    I have updated it to make the advert easier to select and choose how many issues are needed.

    You can see the new form here - http://mk18.web44.net/index3.php#order

    I have started updating the JavaScript code and this is where the problem is.

    I have put the new values of the advert field into the js code along with the price of 1 issue. I have also put in the code that works out the new price based on how many issues are selected.

    The problem is that the prices dont update on the form.

    Can you help me with this . The JS code can be viewed bellow of by right clicking in the index3.php page.

    JS Code :

    Code:
    function formatPrice(theField){
    
      if(isNaN(theField.value)){
    
        theField.select();
    
        theField.focus();
    
        alert('Invalid price: '+theField.value);
    
        return false;
    
      }
    
      price = Math.round(100+theField.value*100)+'';
    
      theField.value = parseInt((price-100)/100)+'.'+price.substr(price.length-2);
    
    }
    
    function calculate() {
    
    adcharge = 0;
    
    designcharge = 0;
    
    thetotal = 0;
    
    vatrate = 0.20;
    
    cardfee = 0;
    
    grand_total = 0;
    
    issue =  0;
    
    var money = grand_total;
    
    if (document.getElementById('advert').value == "FullPage" {adcharge = 188;}
    if (document.getElementById('advert').value == "HalfPage" {adcharge = 200;}
    if (document.getElementById('advert').value == "QuarterPage" {adcharge = 245;}
    if (document.getElementById('advert').value == "EighthPage" {adcharge = 288;}
    
    document.getElementById('ad_charge').value = adcharge;
    
    formatPrice(document.getElementById('ad_charge'));
    
    switch(document.getElementById('issues').value) {
        case 2:
            adcharge *= 2;
            adcharge *= 0.9; 
            break;
        case 3:
            adcharge *= 3;
            adcharge *= 0.85;
            break;
        case 6:
            adcharge *= 6;
            adcharge *= 0.85;
            break;
     }
    
    
    if (document.getElementById('design_service').checked == true){designcharge = 20;}
    
    document.getElementById('design_charge').value = designcharge;
    
    formatPrice(document.getElementById('design_charge'));
    
    
    
    document.getElementById('sub_total').value = adcharge + designcharge;
    
    formatPrice(document.getElementById('sub_total'));
    
    
    
    thetotal = adcharge + designcharge;
    
    
    
    document.getElementById('vat').value = thetotal * vatrate;
    
    formatPrice(document.getElementById('vat'));
    
    
    
    document.getElementById('total').value = thetotal * (1 + vatrate);
    
    formatPrice(document.getElementById('total'));
    
    
    
    if (document.getElementById('payment_method').value == "PayPal") {cardfee = ((thetotal * (1 + vatrate)) * 0.024)+0.24;}
    
    document.getElementById('card_fee').value = cardfee;
    
    formatPrice(document.getElementById('card_fee'));
    
    
    
    document.getElementById('grand_total').value = (thetotal * (1 + vatrate)) + cardfee;
    
    formatPrice(document.getElementById('grand_total'));
    
    return true;
    
    }

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    Your computer IP address *.*.*.* is listed at StopForumSpam database so your visit is blocked
    wtf?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles