¿Cuál es el problema en este código? Lo he intentado y no puedo resolverlo. Soy un novato total en HTML, JavaScript y CSS. Estoy deambulando por Internet, pero creo que me estoy perdiendo algo y es un pequeño error. ¿puedes ayudar amablemente? Tengo que aprender esto para mis próximos proyectos.
aquí está el código
function result() { let a = getElementById("constant").value; let b = getElementById("height").value; let c = getElementById("freq").value; let sum = Number(a) + Number(b) + Number(c); document.getElementById("Calculate").value = sum; } <form> Di-Electric Constant: <input class="text" Placeholder="Enter Value" id="constant" </input> <br> Di-Electric Height: <input class="text" Placeholder="Enter Value" id="height" </input> <br> Operational Frequency: <input class="text" Placeholder="Enter Value" id="freq" </input> <br> <br> <input type="text" id="Calculate" </input> <input type="button" value="Calculate" onclick="result()"> </form> <br/>Es document.getElementById() . Ver: MDN WebDocs: document.getElementById().
El método Document getElementById() devuelve un objeto Element que representa el elemento cuya propiedad id coincide con la cadena especificada. Dado que los ID de los elementos deben ser únicos si se especifican, son una forma útil de obtener acceso a un elemento específico rápidamente.
function result() { let a = document.getElementById("constant").value; let b = document.getElementById("height").value; let c = document.getElementById("freq").value; let sum = Number(a) + Number(b) + Number(c); document.getElementById("Calculate").value = sum; } <!DOCTYPE html> <html> <head> <h1>Microstrip Calculator</h1> <p>Enter the following values in numeric form:</p> </head> <body> <form> Di-Electric Constant: <input class="text"Placeholder="Enter Value" id="constant"</input> <br> Di-Electric Height: <input class="text"Placeholder="Enter Value" id="height"</input> <br> Operational Frequency: <input class="text"Placeholder="Enter Value" id="freq"</input> <br> <br> <input type="text"id="Calculate"</input> <input type="button" value="Calculate" onclick="result()"> </form> <br/> </body> </html>