Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:49:26+00:00 2026-06-04T04:49:26+00:00

Hello javascript experts! I’m a novice here, trying to create a script to add

  • 0

Hello javascript experts!

I’m a novice here, trying to create a script to add up membership fees on a website (I’m a volunteer). Any help is greatly appreciated.

I used this website: http://www.javascript-coder.com/javascript-form/javascript-calculator-script.phtml to set up my html.

It worked just fine (I set up 3 functions, one to calculate the membership price, another for the postage and the other the total amount due – I have not included them below but know they work fine).

UNTIL I realized that the value of postage (which I had calculated only using the first drop-down menu: id=country) was also dependant on the amount in the second drop down menu (the second drop-down menu’s id: membership_type). That is to say, the postage is not only determined by country but also by membership type. I tried to set up a script that would vary the value of the postage depending on the value of the membership type but it isn’t working.

I’m not a coder as you can tell so I’ve spent a lot of time looking for the correct way to do this but have come to a deadend….


    var membership_prices = new Array();
    membership_prices["regular"]=40;
    membership_prices["student"]=24;
    membership_prices["emeritus"]=24;
    membership_prices["regularplus"]=62;
    membership_prices["studentplus"]=46;
    membership_prices["emeritusplus"]=46;

    var extra_postage_cost = new Array();
    extra_postage_cost["USA"]=0;
    extra_postage_cost["Canada"]=0;

    <!-- this is the part that needs work: Edited since original post -->
       extra_postage_cost["Other_Country"]
   if (document.getElementById('membership_type').value =="regular")
       extra_postage_cost["Other_Country"]=8;
   else if (document.getElementById('membership_type').value =="student")
       extra_postage_cost["Other_Country"]=8;
   else if (document.getElementById('membership_type').value =="emeritus")
       extra_postage_cost["Other_Country"]=8; 
   else if (document.getElementById('membership_type').value =="regularplus")
       extra_postage_cost["Other_Country"]=16;
   else if (document.getElementById('membership_type').value =="studentplus")
       extra_postage_cost["Other_Country"]=16;
   else if (document.getElementById('membership_type').value =="emeritusplus")
       extra_postage_cost["Other_Country"]=16;
   else 
       extra_postage_cost["Other_Country"]=0;
   <!-- end of what I believe needs work -->

Here is the rest of the code:

    function getMembershipPrice ()
        {
        var membershipPrice=0;
        var theForm = document.forms["membershipform"];
        var selectedMembership = theForm.elements["membership_type"];
        membershipPrice = membership_prices[selectedMembership.value];
        return membershipPrice;
        }

    function getExtraPostagePrice ()
        {
        var extraPostagePrice = 0;
        var theForm = document.forms["membershipform"];
        var selectedPostage = theForm.elements["country"];
        extraPostagePrice = extra_postage_cost[selectedPostage.value];
        return extraPostagePrice;
        }

    function getAmountDue()
        {
        var amountDue = getMembershipPrice() + getExtraPostagePrice();
        document.getElementById('amountDue').innerHTML ="Amount Due $"+amountDue;
        }

In the drop-down menus themselves I have this kind of code inside the brackets for each drop-down menu:

   select name="membership_type" id="membership_type" onchange="getAmountDue()"
   select name="country" id="country" onchange="getAmountDue()"     
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:49:28+00:00Added an answer on June 4, 2026 at 4:49 am

    I assume the country drop down is defaulted to USA. If this is the case, simply add an “onchange” event listener to the dropdowns that call a function to update the extra charge.

    So instead of having an array object for extra postage, just have a variable extraPostage initially set to zero and update it when the drop downs change.

        var extraPostage = 0;
    
        function onSelectChange(){
          var countrySelect = document.getElementById('countrySelect'); 
          var typeSelect = document.getElementById('membership_type');
          if(countrySelect.value != "Other Country"){
            extraPostage = 0;
            return;
          }
          else{
            var type = typeSelect.value;
            switch(type){
              case "regular":
                extraPostage = 8;
                break;
              case "student":
                extraPostage = 8;
                break;
              case "emeritus":
                extragPostage = 8;
                break;
              //keep going for each different possibility
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

intro Hello, I'm trying to develop some plugin or / and object in javascript,
Inside my index.html.erb <script type= text/javascript> var msg = Hello World ; </script> i
Here is google's hello world code for v3: http://code.google.com/apis/maps/documentation/javascript/tutorial.html#HelloWorld this loads and displays the
I'm beginning to learn javascript and I wrote an infinite loop <script> while(1==true){ document.write(hello
hello im new and learning javascript. I'm trying to make a program of addition
hello im trying to make something like github treeslider im new to javascript.. but
Hello I have some javascript code, a script included inside my page. I want
Possible Duplicate: Count bytes in textarea using javascript Hello everyone. I am trying to
Hello I have worked with regular tables and javascript to add new rows at
Hello everyone is there any possibly to fetch data from mysql databases in javascript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.