1
Guys, I’m trying to get the isolated value of some inputs when typed in the input.
I can even log in the entered value. eg: console.log(topLeft.value), which returns the value that is present in the input at the moment and something 'Undefined'.
I wanted the value that is present in the input to become the value of a variable.
I have tried to create variables outside the functions with the corresponding side name (ex Let topLeft;) but it does not store the input value.
I’m a beginner in the subject and I wanted to know where I’m going wrong.
function getElemento(getElement) {
topLeft = getElement("tl");
topRight = getElement("tr");
bottomLeft = getElement("bl");
bottomRight = getElement("br");
}
function addEvento(addEvent){
addEvent(topLeft);
addEvent(topRight);
addEvent(bottomLeft);
addEvent(bottomRight);
}
window.onload = () => {
function getInputValue() {
let inputValue = this.value;
return inputValue
};
function getElement(id){
let element = document.getElementById(id);
return element
};
function addEvent (side){
side.addEventListener("keypress", getInputValue);
};
getElemento(getElement);
addEvento(addEvent)
}
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="js/value.js"></script>
<title>Document</title>
</head>
<body>
<form action="">
<p>
<label for="top-left">Top Left:</label>
<input id="tl" name="top-left" type="number" value="0">
</p>
<p>
<label for="top-right">Top Right:</label>
<input type="number" id="tr" name="top-right" value="0">
</p>
<p>
<label for="bottom-left">Bottom Left:</label>
<input type="number" id="bl" name="bottom-left" value="0">
</p>
<p>
<label for="bottom-right">Bottom Right:</label>
<input type="number" id="br" name="bottom-right" value="0">
</p>
</form>
</body>
</html>
Put HTML to get a sense of how the code works.
– Augusto Vasques
HTML code added.
– Samyr
You want to take a variable from inside the callback of the event?
– Luiz Felipe
I believe so, I wanted a variable with the input value, at the moment the value is entered, the callback of the event extracts the value gives variable that contains the input and returns its value, but I do not see how to extract it
– Samyr
What do you want to do with this input value? I still don’t understand your goal
– Sergio
Later use as values for a border-Radius in css, but it will be another learning
– Samyr
You can return the values of
inputs
for four global variables? One specific for each input?– Augusto Vasques
That’s the goal, how I should proceed ?
– Samyr