“TypeScript Docum.getElementById Value” Código de respuesta

La propiedad Value no existe en el tipo htmlelement.

document.getElementById() returns the type HTMLElement which does not contain a value property.
The subtype HTMLInputElement does however contain the value property.

So a solution is to cast the result of getElementById() to HTMLInputElement like this:

var inputValue = (<HTMLInputElement>document.getElementById(elementId)).value;
<> is the casting operator in typescript.
See TypeScript: casting HTMLElement: https://fireflysemantics.medium.com/casting-htmlelement-to-htmltextareaelement-in-typescript-f047cde4b4c3

The resulting javascript from the line above looks like this:

inputValue = (document.getElementById(elementId)).value;
i.e. containing no type information.
Vivacious Vendace

TypeScript Docum.getElementById Value

<script>
function gotowhatsapp() {
    
    var name = document.getElementById("name").value;
    var email = document.getElementById("email").value;
	var phone = document.getElementById("phone").value;
	var whats = document.getElementById("whats").value;
    var service = document.getElementById("service").value;

    var url = "https://wa.me/919843341999?text=" 
    + "Name: " + name + "%0a"
    + "Email: " + email  + "%0a"
	+ "Phone: " + phone + "%0a"
	+ "whats: " + whats + "%0a"
    + "Service: " + service; 

    window.open(url, '_blank').focus();
}
</script>
Ugly Unicorn

Respuestas similares a “TypeScript Docum.getElementById Value”

Preguntas similares a “TypeScript Docum.getElementById Value”

Más respuestas relacionadas con “TypeScript Docum.getElementById Value” en TypeScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código