JavaFX: We are experiencing issues with our JavaScript file when we compile the HTML and add the link to the header. What could be causing this problem?

There is a need for the user to be able to change the value, and as a result, the numbers should automatically update. I am facing this issue where the values are not changing correctly. Additionally, I was wondering if it is feasible to link a JS file in an HTML document to run within a JavaFX webView?

var numbersToChange;
var multiplier;

function pageLoad() {
  var inputBox = Number(document.getElementById("servingInputBox").value);
  multiplier = new Array();
  numbersToChange = document.getElementsByClassName("numberToChange");

  for (i = 0; i < numbersToChange.length; i++) {
    multiplier[i] = Number(numbersToChange[i].innerHTML) / inputBox;
  }
}

function changeNumbers() {
  var inputboxValue = Number(document.getElementById("servingInputBox").value);

  for (i = 0; i < numbersToChange.length; i++) {
    numbersToChange[i].innerHTML = (Math.trunc((inputboxValue * multiplier[i]) * 10)) / 10;
  }
}

function increase() {
  var inputBox = Number(document.getElementById("servingInputBox").value);

  document.getElementById("servingInputBox").value = (Math.trunc(inputBox * 10) + 10) / 10;

  changeNumbers();
}

function decrease() {
  var inputBox = Number(document.getElementById("servingInputBox").value);
  var newNumber = (Math.trunc(inputBox * 10) - 10) / 10;

  if (newNumber >= 0) {
    document.getElementById("servingInputBox").value = newNumber;
    changeNumbers();
  }
}

function enter(e) {
  if (e.keyCode == 13) {
    var inputBox = Number(document.getElementById("servingInputBox").value);

    document.getElementById("servingInputBox").value = Math.trunc(inputBox * 10) / 10;

    changeNumbers();
  }
}
@font-face {
...
<html>
...

</html>

If anyone has any insights or solutions regarding this matter, please do share your knowledge.

Answer №1

Make sure to add the JavaScript file in the head section of your HTML document. Additionally, it seems like the CSS file is not loading properly. Here is the recommended structure for the head section:

<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>XYZ</title>
<link rel="stylesheet" href="style/custom.css"/>
<script src="scripts/main.js"></script></head>

Furthermore, create folders named 'style' and 'scripts' parallel to your HTML file path. Place the CSS file as 'custom.css' in the 'style' folder and JS file as 'main.js' in the 'scripts' folder respectively. Following these steps should resolve the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generating a Transform stream with ExcelJS to produce xlsx files

Currently, I am utilizing the ExcelJS module and creating a wrapper to suit my specific needs. This wrapper implements the Transform Stream API, and surprisingly, the node version being used is 0.10.40. The ExcelJS module offers a stream API, and based on ...

Creating dynamic animations by shifting the hue of an image on a canvas

Recently, I've been exploring the world of canvas tags and experimenting with drawing images on them. My current project involves creating a fake night/day animation that repeats continuously. After trying various approaches like SVG and CSS3 filters ...

What is the technique to activate the final item on the chart using Chart.js?

Is there a way to highlight the last element in the data, particularly July, on a JavaScript diagram? Check out this example: https://codepen.io/pichugin/pen/eYgdvBx [https://codepen.io/pichugin/pen/eYgdvBx][1] ...

What is the process for passing an Object from JavaScript to an Action class in Struts 2?

Within my Action class, there exists an object of the class that is a POJO. public class ConfigureTspThresholdAction extends ActionSupport implements SessionAware, ModelDriven<GmaThresholdParameter>{ private Map<String,Object> session ...

What is the best way to add table pagination at the bottom of a table?

Can someone provide guidance on implementing table pagination for the material-ui table below? The documentation is a bit unclear: <Table ria-label="a dense table"> <TableHead> <TableRow> ...

The columns in the row are not fully filling up the container

I have a container with two rows inside. One of those rows contains several columns. My goal is to have four columns per line on mobile devices, which I achieved using "row-cols-4". However, on larger screens, I want all the columns to be on the same line, ...

Issue with Firefox compatibility in Backbone.js

Greetings! I am currently utilizing Backbone.js and require.js for my application, experiencing difficulty with template rendering in Firefox. Interestingly, it works without issues in both Chrome and IE. Allow me to present the code responsible for rende ...

Using Flask to instantaneously respond to asynchronous Node.js await calls

I offer two different services, service A which is based on Node.js and service B which uses Flask. There is an endpoint on service A that calls the endpoint of service B in the following manner: const response = await axios.get( endpoint_url ...

Guide to configuring a robust schema and validation with joi

Currently in the process of setting up validation using the joi package, encountering syntax-related issues along the way. The schema in place is simple, checking for a valid number and verifying if the ID exists in the database. export default router.pos ...

Node.JS Plugin Management - Enhance Your Application with Customized

Currently, I am deeply involved in the development of a complex application using Node.JS, built on top of Express. I decided to implement a flexible plugin system to make things easily plug-and-play. The structure of this system consists of: root/ | p ...

Retrieve various JSON objects from a multipart HTTP response

I am currently utilizing Apache HttpClient to interact with a web service that sends back a multipart/form-data response containing JSON. I am encountering challenges in extracting each individual JSON string from the response so I can effectively analyze ...

Angular is unable to validate the preflight response

I'm currently trying to run a test using the Apiary API like so: $scope.createAsset = function () { $http({ method: 'POST', url: 'http://polls.apiblueprint.org/createStory', headers: {'Access-Control-Allow-Origi ...

Tips for ensuring jwt token is not lost when refreshing a page in an angularjs app

My project involves authorizing users using jwt tokens, but I am facing an issue where the token is lost upon page refresh and subsequent requests to the server do not include the token. The setup includes storing the token in local storage and utilizing ...

Removing an element from an array within each subdocument using Mongoose

In my User Model, I have a cart that stores products (only the id). When I need to remove a product from the store, it should also be removed from all users' carts. I attempted this code: User.update({ $pull: {'cart.items': {productId: prod ...

Implementing a blur effect on a CSS loader

I have successfully implemented a loader feature where a loading animation is displayed upon clicking the submit button, indicating that the form submission is in progress. However, I am encountering an issue when trying to apply a blur effect to the entir ...

Dropdown functionality in JavaScript and Bootstrap

Struggling with getting the bootstrap dropdown to change class on click? Don't worry, I've managed to make it change from "+" to "-", but now I'm facing an issue. When I click on the second dropdown, the one I clicked before doesn't cha ...

Having trouble displaying values from nested JSON in a datatable

Response from server : ["{\"CLIENT\":[{\"tranche\":\"1-4\",\"prix\":\"65.96\",\"currency\":\"E\"}],\"DISTRIBUTEUR\":[{\"tranche\":\"1-4\",\"prix\ ...

I am looking to generate div elements using JavaScript to avoid the tedious task of individually creating numerous divs

Instead of manually typing out multiple div tags in the HTML, I would like to dynamically generate them using JavaScript and display them on the page. Below is an attempt at achieving this, but it appears to not be functioning correctly. var arr = {}; f ...

The outcome of a function within the $.ajax method is transformed into a string

Trying to pass an array of IDs using the $.ajax data variable is proving to be a challenge. The array is generated by a function, and I've noticed that if I define this function outside of the $.ajax call, it works fine. However, when I place the same ...

Tips for creating a unit test for a React Component utilizing the useEffect hook and asynchronous fetch

Starting from a basic create-react-app setup, I am diving into the world of unit testing to enhance my skills. The goal is to update the main App component to fetch data from a local node API and display it as a string response. However, I'm encounter ...