Help with function



Can someone help me to know what its wrong with this function? Its not running and i cant figure out what its wrong, thanks:


  <legend>Ejercicio 5</legend>
  <label for="Valor1">Valor1</Label>
  <input type="number" id="Valor1_id" name="Valor1" placeholder="Ingresar Valor1"><br>
  <label for="Valor2">Valor2</label>
  <input type="number" id="Valor2_id" name="Valor2" placeholder="Ingresar Valor2"><br>
  <input type="button" id="btnCalcular" value="Calcular"><br>
	 <div id="resultado1"></div>
	 <div id="resultado2"></div>
	function btnCalcular(){
	 var Valor1=document.getElementById("Valor1_id").value;
	 var Valor2=document.getElementById("Valor2_id").value;
	 var Valor1=document.getElementById("Valor1_id").value;
	 var Valor2=document.getElementById("Valor2_id").value;



You have some elements chained. Move the <div> to before the <form> and that will cure it.

As for your script, you do not need to repeat the getElementById.

// define and cache node objects in advance
var valor1 = document.getElementById("Valor1_id");
var valor2 = document.getElementById("Valor2_id");
var resultado1 = document.getElementById("resultado1");
var resultado2 = document.getElementById("resultado2");

function btnCalcular() {
    resultado1.innerHTML = valor1.value + valor2.value;
    resultado2.innerHTML = valor1.value * valor2.value;

Edited => value() -> value


thank you, for other side, i cant see the error on the following function, the n°2 excercise, can you please help me:

        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
        <script src="js/codigo.js" type="text/javascript"></script>
        <h1>Ejercicio 1</h1>
        <label for="txtNombre">Nombre</label>
        <input type="text" id="txtNombre"><br>
        <label for="txtApellido">Apellido</label>
        <input type="text" id="txtApellido"><br>
        <input type="button" id="btnprocesarEj1" value="Procesar">
        <p id="pResultado"></p>
            <label for="txtvalor1">valor1</label>
            <input type="text" id="txtvalor1"><br>
            <label for="txtvalor2">valor2</label>
            <input type="text" id="txtvalor2"><br>
            <input type="button" id="btnsumaEj2" value="suma">
            <p id="pMostrar"></p>


function iniciar() {

function procesarEjercicio1() {
var txtNombre=$("#txtNombre").val();
var txtApellido=$("#txtApellido").val();
var txtResultado=txtApellido +","+ txtNombre;


function procesarEjercicio2(){
    var txtvalor1=parseInt($("#txtvalor1").val());
    var txtvalor2=parseInt($("#txtvalor2").val());
    var txtMostrar=txtvalor1+txtvalor2;
type or paste code here



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.