How to output an input from javascript

1

A help, how would the result put it in an input, to save the result in a database? To remove the div, please help

function calcularEdad()
		{
			var fecha=document.getElementById("user_date").value;
			if(validate_fecha(fecha)==true)
			{
				var values=fecha.split("-");
				var dia = values[2];
				var mes = values[1];
				var ano = values[0];

				var fecha_hoy = new Date();
				var ahora_ano = fecha_hoy.getYear();
				var ahora_mes = fecha_hoy.getMonth()+1;
				var ahora_dia = fecha_hoy.getDate();

				var edad = (ahora_ano + 1900) - ano;
				if ( ahora_mes < mes )
				{
					edad--;
				}
				if ((mes == ahora_mes) && (ahora_dia < dia))
				{
					edad--;
				}
				if (edad > 1900)
				{
					edad -= 1900;
				}

				var meses=0;
				if (ahora_mes>mes)
					meses=ahora_mes-mes;
				if (ahora_mes<mes)
					meses=12-(mes-ahora_mes);
				if (ahora_mes==mes && dia>ahora_dia)
					meses=11;

				var dias=0;
				if (ahora_dia>dia)
					dias=ahora_dia-dia;
				if (ahora_dia<dia)
				{
					ultimoDiaMes=new Date(ahora_ano, ahora_mes, 0);
					dias=ultimoDiaMes.getDate()-(dia-ahora_dia);
				}

				document.getElementById("result").innerHTML="Tienes "+edad+" años";
			}
			else
			{
				document.getElementById("result").innerHTML="La fecha "+fecha+" es incorrecta";
			}

    
asked by GeorgeOtalvaro 22.10.2018 в 03:16
source

1 answer

1

To pass a value to an input, instead of doing this

document.getElementById("result").innerHTML="Tienes "+edad+" años";

Please install it for the following

document.getElementById("result").value ="Tienes "+edad+" años";

By using value you can dynamically assign the value generated to the content of a input

    
answered by 22.10.2018 в 03:42