0
I need two functions that pick up the value of one input
and send it to another input
this value +2, had already asked this question here but went to +3 and got the solution, however I did another function with another name and other fields, and the result was NaN
. Here’s the +3 code that works:
function tenta() {
if(document.getElementById('ciclo').value == "")
{
document.getElementById('ciclo2').value = "2013"; //placeholder
document.getElementById('ciclo2').style.color = "#bfbfbf";
}else
{
document.getElementById('ciclo2').style.color = "black";
var x = document.getElementById('ciclo').value;
document.getElementById('ciclo2').value = parseFloat(x) + 3;
}
}
and the equal function, but returns NaN
:
function numeros2()
{
if(document.getElementById('ciclo3').value == "")
{
document.getElementById('ciclo4').value = "2013"; //placeholder;
document.getElementById('ciclo4').style.color = "#bfbfbf";
}else
{
document.getElementById('ciclo4').style.color = "black";
var xy = parseInt(document.getElementById('ciclo4').value);
document.getElementById('ciclo4').value = xy + 2;
}
}
I’ve tried the parseFloat
, but it also doesn’t work.
Empty values are Nan itself. I think your problem is in the if. Lse, it doesn’t have much to do with the value. You test the cycle, but you change the cyclo2. Then test cyclo3, but apply to cyclo4. Is that right? Put a [mcve] on JS Fiddle and send us the link to test.
– Bacco
It’s the same HTML as the other question?
– Sergio
Yes Sergio and the same
HTML
. The inputs have aonkeyup
.– programmer2016
Hello, I made a jsfiddle but I couldn’t replicate its embarrassment. http://jsfiddle.net/q6jGr/196/ You can create to help then.
– Tiago Gomes
is exactly that Tiago Gomes, but instead of being necessary to click, is made an
onkeyup
. but the mistake is just that, one works on the other.– programmer2016