Doubt with function in javaScript

0

I'm trying to figure out what happens after the click of a submit button on one page, to do exactly the same thing on another. On the page I am looking at and the code is written this:

<button onclick= function (ev) {
ev = ev || window.event;
r = Nwa_SubmitForm("forme1c43235_weblogin","ID_forme1c43235_weblogin_submit");
ev.returnValue = r;
return r;
}>Click me</button>

It seems that it is calling the function Nwa_SubmitForm, passing as parameter the form id and another parameter that I do not know what it is. The "ev" that the function receives as parameter is the button click (the event)?

I know the question is a bit vague. But could someone try to start helping me understand what this code is doing? Or where can I start trying to understand? Obriagda

    
asked by anonymous 01.08.2018 / 20:18

1 answer

0

The function in question is to do the handle of the event click (attribute onclick in HTML). Given this in mind, the parameter in question ( ev ) is the JavaScript event interface, which has a number of properties and methods related to the event itself.

A simple example:

function handleClick (eventInterface) {
  eventInterface.preventDefault();
  
  alert('A ação padrão deste evento foi prevenida!');
}

const link = document.querySelector('#link');
link.addEventListener('click', handleClick);
<a href="/" id="link">Clique em mim.</a>

In the example above, I created a link that in theory, when clicked, should take us to the main page here of StackOverflow, but since we use the preventDefault() method in the event interface, the default action was prevented. / p>

This is only one of the methods present in this interface and was used as an example only. Now that you know what the event interface is, you can take a look at the documentation.

Note that for teaching purposes, I have named the parameter as eventInterface , but most people use event , ev or e . But as it is a parameter, you can name it as you prefer. :)

Reference:

01.08.2018 / 21:37