Quote from llazzari on February 26, 2025, 5:22 pmgood morning, I can't figure out where the problem is.
Inside a div I have 55 input boxes with the same class.
what I want to do is "paste in an input box 55 values/numbers and through a button in which I have inserted this code:
which should insert the numbers in each input box but why does this happen?function distribuzioneNumeri() {
// Get the value inserted in the numbers field
let input = document.getElementById("inputNumbers").value;// Remove any extra spaces and separate the numbers (this only considers numbers and commas/spaces)
let numeri = input.split(/[\s,]+/).filter(num => num.match(/^\d+$/)); // Remove words and filter numbers// Check that there are exactly 55 numbers
if (numeri.length !== 55) {
alert("You must enter exactly 55 numbers!");
return;
}// Select all text boxes with the class "numero-box"
let caselle = document.getElementsByClassName("number-box");// Check if there are enough boxes
if (boxes.length < numbers.length) {
alert("There are not enough text boxes!");
return;
}// Distribute the numbers in the boxes
for (let i = 0; i < numbers.length; i++) {
boxes[i].value = numbers[i]; // Insert the number in the boxes
};}
I take these numbers from a site of the game of eight, including the name of the wheels, the code should discard the name of the wheels and insert the values in each box.
If you have any suggestions, thanks?
good morning, I can't figure out where the problem is.
Inside a div I have 55 input boxes with the same class.
what I want to do is "paste in an input box 55 values/numbers and through a button in which I have inserted this code:
which should insert the numbers in each input box but why does this happen?
function distribuzioneNumeri() {
// Get the value inserted in the numbers field
let input = document.getElementById("inputNumbers").value;
// Remove any extra spaces and separate the numbers (this only considers numbers and commas/spaces)
let numeri = input.split(/[\s,]+/).filter(num => num.match(/^\d+$/)); // Remove words and filter numbers
// Check that there are exactly 55 numbers
if (numeri.length !== 55) {
alert("You must enter exactly 55 numbers!");
return;
}
// Select all text boxes with the class "numero-box"
let caselle = document.getElementsByClassName("number-box");
// Check if there are enough boxes
if (boxes.length < numbers.length) {
alert("There are not enough text boxes!");
return;
}
// Distribute the numbers in the boxes
for (let i = 0; i < numbers.length; i++) {
boxes[i].value = numbers[i]; // Insert the number in the boxes
};
}
I take these numbers from a site of the game of eight, including the name of the wheels, the code should discard the name of the wheels and insert the values in each box.
If you have any suggestions, thanks?
Quote from luishp on February 27, 2025, 6:59 pm@llazzari VisualNEO Web uses NeoScript for most of the tasks you are trying to do.
For example, you don't need any code for getting the value from a TextInput. It's just stored in the assigned variable.
You can use StrParse to split a string.
Converting to a number is also a one command task using ToNumber.Anyway, regarding JavaScript:
The issue lies in a few small mistakes in your JavaScript code. Here's a breakdown of what's going wrong and how to fix it:
Issues Identified:
Variable Naming Inconsistencies:
- You defined the array as
numeri
, but later referred to it asnumbers
.- Similarly, you selected elements using
caselle
, but then referred to them asboxes
.No Declaration for
boxes
:
- You used
boxes.length
without definingboxes
. You meant to usecaselle
.Corrections Needed:
- Consistently use either Italian or English for your variable names to avoid confusion.
- Ensure that you're using the correct variable names in all parts of your code.
Corrected Code:
function distribuzioneNumeri() { // Get the value inserted in the numbers field let input = document.getElementById("inputNumbers").value; // Remove any extra spaces and separate the numbers let numeri = input.split(/[\s,]+/).filter(num => num.match(/^\d+$/)); // Check that there are exactly 55 numbers if (numeri.length !== 55) { alert("You must enter exactly 55 numbers!"); return; } // Select all text boxes with the class "number-box" let caselle = document.getElementsByClassName("number-box"); // Check if there are enough boxes if (caselle.length < numeri.length) { alert("There are not enough text boxes!"); return; } // Distribute the numbers in the boxes for (let i = 0; i < numeri.length; i++) { caselle[i].value = numeri[i]; // Insert the number in the boxes } }
Key Changes Made:
- Replaced
numbers
withnumeri
everywhere.- Replaced
boxes
withcaselle
.- Checked the length of
caselle
instead of the undefinedboxes
.Additional Suggestions:
- Make sure that all input boxes have the class
number-box
.- Verify that the input field where you paste numbers has the
"inputNumbers"
.- If the numbers are copied from a website, ensure there are no hidden characters or special symbols.
@llazzari VisualNEO Web uses NeoScript for most of the tasks you are trying to do.
For example, you don't need any code for getting the value from a TextInput. It's just stored in the assigned variable.
You can use StrParse to split a string.
Converting to a number is also a one command task using ToNumber.
Anyway, regarding JavaScript:
The issue lies in a few small mistakes in your JavaScript code. Here's a breakdown of what's going wrong and how to fix it:
Variable Naming Inconsistencies:
numeri
, but later referred to it as numbers
.caselle
, but then referred to them as boxes
.No Declaration for boxes
:
boxes.length
without defining boxes
. You meant to use caselle
.function distribuzioneNumeri() { // Get the value inserted in the numbers field let input = document.getElementById("inputNumbers").value; // Remove any extra spaces and separate the numbers let numeri = input.split(/[\s,]+/).filter(num => num.match(/^\d+$/)); // Check that there are exactly 55 numbers if (numeri.length !== 55) { alert("You must enter exactly 55 numbers!"); return; } // Select all text boxes with the class "number-box" let caselle = document.getElementsByClassName("number-box"); // Check if there are enough boxes if (caselle.length < numeri.length) { alert("There are not enough text boxes!"); return; } // Distribute the numbers in the boxes for (let i = 0; i < numeri.length; i++) { caselle[i].value = numeri[i]; // Insert the number in the boxes } }
numbers
with numeri
everywhere.boxes
with caselle
.caselle
instead of the undefined boxes
.number-box
."inputNumbers"
.