Desktop app, using Electron and nodejs

Asked

Viewed 188 times

1

Hello, I wonder how I can pass the value of a field that is in (index.html) to a function that is (data-user.js).

I have an application in nodejs using Electron, the main calls index.html, which mounts the screen, and has some fields, NAME, EMAIL and a button. When I press the button I want to send the value of the fields to a function that is in a class (.js).

    <form method="post" action=""> 
      <h1>Ativar Notificações</h1> 

      <p> 
        <label for="nome_cad">Seu nome</label>
        <input id="nome_cad" name="nome_cad" required="required" type="text" placeholder="nome" />
      </p>

      <p> 
        <label for="email_cad">Seu e-mail</label>
        <input id="email_cad" name="email_cad" required="required" type="email" placeholder="[email protected]"/> 
      </p>

      <p>
        <button onclick="sendData()" > Ativar </button>
      </p>
    </form>

I’m trying to do it this way, but it didn’t work:

<script type="text/javascript">
  function sendData(){
    const dataUser = require('./data-user');

    dataUser(document.getElementById('nome_cad').value,  document.getElementById('email_cad').value);

  }

</script>

The data-user class is thus:

module.exports = async (nome, email) => {

console.log(nome);
console.log(email);

}

Thank you.

1 answer

0


Tries

<script src="./data-user.js"></script>
<script type="text/javascript">
  function sendData(){
  dataUser(document.getElementById('nome_cad').value,  document.getElementById('email_cad').value);

  }
</script>

And in the ./data-user.js

function dataUser(nome, email){
  console.log(nome);
  console.log(email);
}

Browser other questions tagged

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