Doubt with Function in Java

Asked

Viewed 74 times

0

I’m trying to figure out what happens after clicking a Ubmit button on one page, to do exactly the same thing on another. On the page I’m 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 id of the form and another parameter that I do not know what it is. The "Ev" the function receives as parameter is the click of the button (the event)?

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

1 answer

0

The purpose of the function in question is to Handle of the event click (attribute onclick in HTML). With this in mind, the parameter in question (ev) is the event interface of Javascript, which has a number of properties and methods relating 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 lead us to the main page here of Stackoverflow, but how we use the method preventDefault(), present in the event interface, the standard action was prevented.

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

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

Reference:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.