Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

397
Views
Retrieving variable values from Javascript file rather than HTML/CSS

I apologize if this is a simple issue but I've spent a long time being completely stuck, all guides are retrieving from the HTML file, and as such I have no clue where to even begin or what to search.

        <form class="container" method="post">
            <div class="form-group">
                <input class="form-control" name="title">
            </div>
            <textarea class="form-control" name="content"></textarea>
            <button>add to mongodb</button>
        </form>

From this code in the HTML file, I can retrieve the values inputted,

app.post("/", function(req, res) {
    let newGameData = new gameData ({
        score: req.body.title,
        jumps: req.body.content,
    });
    newGameData.save();
    res.redirect('/')
})

However, instead of retrieving values from HTML forms, I want to retrieve variables from a game inside the HTML, the javascript file containing the below

var score = [];
var jumps = [];

These variables are appended to as the score increases and as the character jumps, at the end of each life, I want to append it to the score, and periodically retrieve this data to be uploaded onto MongoDB, and vice versa I retrieve and display the highscore.

I was thinking to write to a json file that could be uploaded onto MongoDB, though I have no clue how to go about it or if it's valid at all, any help would be greatly appreciated, thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As suggested in the comments, learn about Ajax. This is a sample code:

let newGameData = {
  score: title,
  jumps: content,
};

$.post("/", newGameData, function(result) {
  console.log(result)
})

and on the server side, don't redirect, but rather res.send(result).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!