ASP.Net MVC and querySelectorAll usage
-
Please see the code.
using (Html.BeginForm("Login", "Default", new { ReturnUrl = ViewBag.ReturnUrl, data = Request.QueryString["data"] }, FormMethod.Post,
new
{
id = "idtest1",
onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)",
@class = "form-signin",
role = "form"
}))
{}
specially see this line which is not clear to me. onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)", in the above code BeginForm html helper has been used to render form at runtime. what will happen when form will be submitted ? what this line will do when form submit ? onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)", please help me to understand this JavaScript code objective when form submit. Thanks
-
Please see the code.
using (Html.BeginForm("Login", "Default", new { ReturnUrl = ViewBag.ReturnUrl, data = Request.QueryString["data"] }, FormMethod.Post,
new
{
id = "idtest1",
onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)",
@class = "form-signin",
role = "form"
}))
{}
specially see this line which is not clear to me. onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)", in the above code BeginForm html helper has been used to render form at runtime. what will happen when form will be submitted ? what this line will do when form submit ? onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)", please help me to understand this JavaScript code objective when form submit. Thanks
That line sets the
onsubmit
attribute on the<form>
element to the specified Javascript string. It's an old way of attaching an event handler to an element. When the form is submitted, all buttons on that form will have theirdisabled
property set tofalse
. But that won't actually accomplish anything; a button's name and value are only submitted with the form if you click on that button, and you can't click on a disabled button.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
That line sets the
onsubmit
attribute on the<form>
element to the specified Javascript string. It's an old way of attaching an event handler to an element. When the form is submitted, all buttons on that form will have theirdisabled
property set tofalse
. But that won't actually accomplish anything; a button's name and value are only submitted with the form if you click on that button, and you can't click on a disabled button.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer