Hi I am working in JavaScript, jQuery and MVC application.
document.forms['shipform'].submit();
Here I submit my form like this.
Totally I have three form in this page.
This is my form:
<% using (Html.BeginForm("OrderShipments", "Shipments", FormMethod.Post, new { @id = "shipform" })) // Creates <form>
{%>
<input type="hidden" id="Hiddenid" name="orderId" />
<input type="submit" value="book" style="display: none" />
<%} %>
It is not working in Chrome, but it works in Firefox.
document.forms[0].submit();
If I use forms[0]
which form would it take if I have three form in single page?
The code you have will submit the form based on its name:
document.forms['shipform'].submit();
^^^ form name not ID
If you want to submit the form by its ID then use:
document.getElementById('shipform').submit();
Or jQuery:
$('#shipform').submit();
If you're using jQuery you can do this:
$('#shipform').submit();
Assuming that code outputs a form with ID="shipform"
<form id="shipform"></form>
You can "get" the form with getElementById()
, then submit()
it:
document.getElementById("shipform").submit();
This should send in your form.
(Assuming the { @id = "shipform" }
sets the id
on your form to "shipform"
)
If you use forms[0]
, it should use the "first" form on your page, so the one that's loaded first, in your html.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.