When is use typescript,vs tell me HTMLElment will don't have the submit property.
document.getElementById('case_form').submit();
How can i use form.submit()
in the typescript file?
Submitting the Form from TypeScript // Import stylesheets import './style. css'; const form: HTMLFormElement = document. querySelector('#myform'); form. onsubmit = () => { const formData = new FormData(form); const text = formData.
If you want to make 100% certain that the submit button cannot be clicked twice, you could disable it in the javascript within the onclick= method of the button. For instance, in the javascript (jquery) below, if the button id was 'send'... This is not 100%. Client side code can very easily be circumvented.
You need to tell TypeScript that this element is in fact a <form>
:
var myForm = <HTMLFormElement>document.getElementById('case_form');
myForm.submit();
The main point here is <newType>value
, which tells TypeScript to convert value
to newType
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With