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 600555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:37:06+00:00 2026-05-13T16:37:06+00:00

I’m working on a JavaScript based page that returns the cost of delivery, depending

  • 0

I’m working on a JavaScript based page that returns the cost of delivery, depending on what the user selects(Region, service(pre 12, etc) and weight). I have muddled my way through as I just don’t know JS.

My questions are:

  1. Can I pass the variable between functions – as detailed in the script below?
  2. Once the above has been achieved, I need to process the variables to display the result, now I could do a massive ifelse, don’t really want to because there will be some 30 odd possibilities. All required info is in a SQL DB so this would be my preferred choice but I’m not sure how to do this with JS, the whole Browser side, Server side issue. Would I need to pass the variables(as above) to PHP (once all 3 are set) to grab the data from the SQL DB? If so, I’m not sure how to do this.
  3. If I do use PHP then the page will have to be reloaded, is it possible to get this to be seamless to the user, i.e., all their selections are still displayed?

    function flag(nation, area) {
      this.nation = nation;
      var el = document.getElementById("desc");
      el.innerHTML = 'The region you have selected is <b>' + area + '</b>';
      document.getElementById("flag").innerHTML = '<img src="images/flags/' + nation + '.jpg">';
    }
    
    function output(service) {
      this.service = service;
      var el = document.getElementById("service-desc");
      el.innerHTML = 'You have selected a <b>' + service + '</b> service.';
      document.getElementById("clock").innerHTML = '<img src="images/clock-' + service + '.png">';
    }
    
    function result() {
      //get varibles(nation & serive) from functions above ~ not sure how to do this!
      //process varibles
      if (nation == "UK" && service == "Standard next day") {
        document.getElementById("result").innerHTML = '£9.99';
      } else if (nation == "UK" && service == "Before 12pm") {
        document.getElementById("result").innerHTML = '£14.99';
      }
      // etc,etc,etc....
      else {
        document.getElementById("a1").innerHTML = "";
      }
    }
    
  • 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-05-13T16:37:06+00:00Added an answer on May 13, 2026 at 4:37 pm

    In javascript if you declare a variable outside a function you can use it from any function, this is a global variable. E.g.

    var x, y;
    function flag(nation,area)
    {
      x = nation;
      y = area;
    }
    function output(service)
    {}    
    function result() {
      //In here you can do whatever you want with x and y
    }
    

    You would be best creating a PHP script that gets your data from the database and returns it to your javascript. The best way to do this would be an AJAX call, this would allow you to seemlessly get the data from the database that you want and only update specific parts of the page rather than the whole page.

    I would recommend having a look at jQuery as it has some very easy to use AJAX methods. It is just a library that wraps javascript and has lots of easy to use functionality, good introduction vids here

    Here is a tutorial on how to use jQuery to call a PHP script which gets data from a database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Probably the best choice is to handle them on Page_Load… May 14, 2026 at 8:18 pm
  • Editorial Team
    Editorial Team added an answer Lucene does not support unary NOT operator. But you can… May 14, 2026 at 8:18 pm
  • Editorial Team
    Editorial Team added an answer You can define #region tags in your code behind files… May 14, 2026 at 8:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.