I have a form on one of my ASP.Net MVC views that I created using the following code
<% using (Html.BeginForm(null, null, FormMethod.Post))
Using this code I have no control as far as I am aware of setting the name of the form. I'm now trying to write a javascript function to submit the form, is this possible without knowing the forms name?
Thanks
The JavaScript form submission can be used for object creation and various attributes can also be used. The attributes can be class, id, tag, etc. Calling by attributes is quite simple, we just need to place the symbols properly.
When we click on the link, the function submitForm() will get executed. This function will get the element object using DOM getElementById() method by passing the form id to this method, then the form will be submitted by using submit() method.
JavaScript can be used in asp.net mvc. If you go for Asp.NET Web forms, there is no need to have a detailed understanding of HTML, CSS or JavaScript as it abstracts all these details and provides automatic plumbing.
You can use jquery to submit the form:
<% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "myForm"})) { %>
(the last part is for htmlAttributes parameter)
just do this:
$("#myForm").submit();
and do not forget to include jquery-1.2.6.js that comes with mvc (or use a higher version).
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