“TypeScript Document.GetElementByID” Ответ

Свойство «значение» не существует на типе «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 Document.GetElementByID

<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

Ответы похожие на “TypeScript Document.GetElementByID”

Вопросы похожие на “TypeScript Document.GetElementByID”

Больше похожих ответов на “TypeScript Document.GetElementByID” по TypeScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования