Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript can't submit form [duplicate]

Tags:

typescript

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?

like image 542
Gongxi Avatar asked May 27 '15 08:05

Gongxi


People also ask

How do I submit a form in TypeScript?

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.

How can stop double click on submit button in JSP?

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.


1 Answers

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.

like image 84
DCoder Avatar answered Oct 02 '22 10:10

DCoder