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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:31:28+00:00 2026-06-17T09:31:28+00:00

I have a file called functions.js where I have the functiom sum which computes

  • 0

I have a file called functions.js where I have the functiom sum which computes the score that a student takes at a test. I want that sum to be printed into a table in the file admin.php so that the administrator sees all the scores that each student has.

So how can I pass the sum variable to another file? I tried calling the function using the onlick action but that didn’t work

  • 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-17T09:31:29+00:00Added an answer on June 17, 2026 at 9:31 am

    I guess you probably want something like this

    document.getElementById('saveScoreButton').onclick = {
      var r = new XMLHttpRequest,
        message = document.getElementById('message'),
        score = sum();
      message.innerHTML = 'Saving your score; please wait a second';
      r.open('get', 'savescore.php?score=' + score, true);
      r.send(null);
      r.onreadystatechange = function () {
        if (r.readyState == 4 && r.status == 200) {
          message.innerHTML = 'Saved your score';
        }
      }
    }
    

    This passes the score to a PHP programme savescore.php when you click a button with id saveScoreButton. The PHP programme then has to retrieve it using $_GET["score"].

    Note that this would be easy for the user to trick if they understand javascript and see what is happening. They could just type ‘savescore.php?score=100’ in the browser’s address bar. If you want a secure solution the javascript should only pass the user’s answers to the PHP programme, which would then mark the test and sum the results.

    It is also possible to use the POST method instead of GET to pass a value:

      ...
      r.open('post', 'savescore.php?score=' + score, true);
      r.send('score=' + score);
      ...
    

    Then pick it up in the PHP programme using $_POST["score"].

    As mentioned in comments, if you want to compare/tabulate scores, then savescore.php will need to store the values in a database or file so that they can be retrieved by admin.php.

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

Sidebar

Related Questions

I have a file called address.php with a few functions in it. I want
Ok, so I have a file called functions.ps1 that contains only function code: something
I have a .ps1 file in which I want to define custom functions. Imagine
i have 20 threads that write with the println() function on a file called
I have a Function in CFC file, which will be called from .cfm file
I have a file called middle.config that is deployed in the same directory as
I have a file (called print_1012720.txt ) that looks like the text shown below.
I have a file called video_2.m4v on my computer, which is being used by
I have a file called header.php that I am including on every page on
I have a file called webpart.cs which is called by one of my masterpages

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.