-2
I created an input in HTML, but I need to put the value of this input in a variable. Yes, I have tried using queryselector
the getelementbyid
and it didn’t work.
I want to make a speed system and only need this variable if you see any more error in my code warn Please.
var b = document.getElementById("botao")
var v1 = document.getElementsByid('num1')
var v2 = document.getElementsByName("n2")
function clicar() {
if (v1 >= v2) {
alert("você estar com uma velocidade alta ")
} else {
alert("voce estar com uma velocidade normal")
}
}
section {
background-color: rgb(88, 230, 255);
border-radius: 10px;
padding: 10px;
background-clip: initial;
background-position: 30px;
font-size: large;
}
body {
background-color: aliceblue;
}
h1 {
text-align: center;
text-shadow: 20px;
scrollbar-shadow-color: rgb(151, 255, 233);
}
h2 {
border-bottom-color: aliceblue;
color: rgb(255, 136, 136);
text-align: center;
font: x-small;
font-family: 'Courier New', Courier, monospace;
}
input#button {
font-style: oblique;
background-color: green;
}
<h1><strong> Bem vindo ao sistema de velocidade do detran</strong></h1>
<section>
<div id="n1">
<input type="number" name="n1" id="num1"> Qual é o limite máximo de velocidade dessa área?
</div>
<input type="number" name="n2" id="num2"> Qual é a sua velocidade?
</section>
<input type="button" value="enviar" onclick="clicar()">
<h2>obrigado por testar</h2>
On the line
var v1 = document.getElementsByid('num1')
is spelled wrong. The correct isvar v1 = document.getElementById('num1')
– Augusto Vasques
Thank you, I’ll run this and see if it works
– Jose Paulo
Ñ worked the ploblema in the code and that qnd puts the speed he never says if only says Else,even with the null value he ignores
– Jose Paulo
The correct is
var v1 = document.getElementById('num1').value;
andvar v2 = document.getElementsByName("n2").value;
lacked to use the propertyvalue
.– Augusto Vasques
All right, thank you very much and custom of converas via instant chat
– Jose Paulo
It was not a scolding, Today I am an old man, but I started programming as a child and I was very humiliated and missed many opportunities for not knowing how to communicate with adults at the time.
– Augusto Vasques
Still thanks, about the code I think there’s something wrong with it put the . value;at the end of the two I don’t know what’s going on,
– Jose Paulo
Do
var v2 = document.getElementsByName("n2")[0].value;
The methodgetElementsByName()
returns an array. Now it works.– Augusto Vasques
Only in v2? Or in v1 tb?
– Jose Paulo
Only the
v2
. That’s where he used the methodgetElementsByName()
– Augusto Vasques
Thanks for Juliet more.... it didn’t work! Let it go I’ll use the old method by the prompts.
– Jose Paulo
Here worked.
– Augusto Vasques
@Josepaulo when asking a question is important to be clear in the title and description, be cautious in spelling and grammar, as well as format the code properly. This makes it much easier to get help.
– tvdias
Only missing comment saying that the variables should be within the Function and that the parole is changed
– user60252
@Was Josepaulo able to verify the answers presented? But forget to accept the one you find most suitable and put in all you find good.
– tvdias