Find out which button was clicked, and make an if

Asked

Viewed 47 times

-1

Good evening, I’m new to web programming I’m having a hard time, knowing if anyone can help me?

I have 2 forms one stands over the other for user only shows one form at a time, the 2 forms have different names and components, one is the login screen, and another the screen to recover the password, one has a login button and another has the reset button, I want when you click one of these buttons to return a string with button name.

example

var nomeBtn

if nomeBtn = 'login' then
 let form = document.getElementById('formLogin');
 let submit = document.getElementById('btnLogin');
elseif nomeBtn = 'redefinir' then
 let form = document.getElementById('formRedefinor');
 let submit = document.getElementById('btnRedefinir');
end if

I used a little VBA with Javascript everything else would be for Javascript, pq know how to program in Vbapor that I used if VBA because I don’t know much the if of Javascript

Somebody help me?

  • This form...' are inputs ?

  • when associating an event like "click" for example to a function, it is possible to pass the element that clicked as parameter, and know what was. I suggest first port your code to javascript and create something basic like the one Handler for the click event, so you can then get to that part of the code that is

  • are inputs within the form

1 answer

0

You can put an eventListener in the document and tell to do what you want in a function, example:

document.addEventListener('click', function(e){ console.log(e.target); });

This will return the element that was clicked, but if you want the id to appear you can put something like inside the function up there:

console.log(e.target.getAttribute('id'));

Try it on and let me know if it works

  • fail, the first login button it does not load anything on the console

  • How was the code after that function I told you about?

Browser other questions tagged

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