question

TZacks-2728 avatar image
0 Votes"
TZacks-2728 asked Bruce-SqlWork edited

ASP.net MVC and querySelectorAll.forEach

What is the meaning of this line onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)",

 using (Html.BeginForm("Login", "Default", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post,
 new
 {
     id = "idMyForm",
     onsubmit = "this.querySelectorAll('button').forEach(i => i.disabled = false)",
     @class = "form-signin",
     role = "form"
 }))
 {
    
 }

Thanks

dotnet-aspnet-generaldotnet-aspnet-core-mvc
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I recommend looking up the JavaScript functions with an Internet search to learn how the functions work.

querySelectorAll()
Array.prototype.forEach()
Button disabled Property
onsubmit Event


1 Vote 1 ·

1 Answer

Bruce-SqlWork avatar image
1 Vote"
Bruce-SqlWork answered Bruce-SqlWork edited

On the rendered form element, JavaScript is declared for the onsubmit attribute. This JavaScript finds all button elements that are a child of the form and disables them. Probably to prevent clicking a second time during the form post. Another common approach is is modal that displays a message.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.