“DocumentScript Document.getElementById Valor” Respostas de código

Propriedade valor não existe no 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

DocumentScript Document.getElementById Valor

<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

Respostas semelhantes a “DocumentScript Document.getElementById Valor”

Perguntas semelhantes a “DocumentScript Document.getElementById Valor”

Mais respostas relacionadas para “DocumentScript Document.getElementById Valor” em TypeScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código