How do I make a data typed in an input go to a java script function?

Asked

Viewed 58 times

0

How do I make the data typed in a form input go to a variable or that is viewed by that variable, the variable in question is:

var emailAddress = "[email protected]";

The form in question is:

<form name="" class="list " id="">
    <ion-list class=" " id="signup-list3">
        <div class="app-icon"></div>
        <label class="item item-input item-floating-label">
            <span style="color: #9F9F9F;" class="input-label">E-mail</span>
            <input style="color: #ffffff;" ng-model="user.email" type="email" placeholder="E-mail">
        </label>
    </ion-list>
    <div style="width: 279px; height: 35px;" class="spacer"></div>
    <button ng-click="firebase.auth();" class=" button button-balanced  button-block  icon-left ion-ios-email-outline " style="border-radius:0px 0px 0px 0px;" id="">Enviar e-mail de redefinição</button>
    <button onclick="Mudarestado('item1', 'item2')" class="button button-balanced  button-block  icon-left ion-ios-email-outline ">Entrar</button>
</form>

I need the email typed in the input <input style="color: #ffffff;" ng-model="user.email" type="email" placeholder="E-mail"> is sent by clicking the button <button ng-click="firebase.auth();" class=" button button-balanced button-block icon-left ion-ios-email-outline " style="border-radius:0px 0px 0px 0px;" id="">Enviar e-mail de redefinição</button> Fill input data and go to variable var emailAddress = "[email protected]"; thus allowing the function of the previously informed button to send the email to the user.

Basic mind the problem and I do not know how I can do so that the data typed in an input is in place of "[email protected]"; of the variable var emailAddress = "[email protected]"; for the rest of the script to send the email to the user who typed in the input.

Currently this script is configured to send the email already configured in this variable in the example [email protected] when the clik of the above mentioned button occurs.

Here follows the example of the doubt script

var auth = firebase.auth();
var emailAddress = "[email protected]";

auth.sendPasswordResetEmail(emailAddress).then(function() {
  // Email sent.
}).catch(function(error) {
  // An error happened.
});

3 answers

0

You can use Jquery to do this. First you need to give an id for this input, for example: id="email"

<input style="color: #ffffff;" ng-model="user.email" type="email" placeholder="E-mail" id="email">

Then using the function change:

$('#email').change(function(){
    emailAddress = $(this).val();
}

But make sure you have Jquery in your code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  • How would I make this application in my code? could you give me an example?

0

According to your question I think some fields are missing. Put the field name in function:

<input style="color: #ffffff;" name="nomeDaVariavel" ng-model="user.email" type="email" placeholder="E-mail">

Put in the form the type you want to pass and an action that’s where you want to go:

<form type="POST" action="nomeDoArquivo.estensao" class="list" >

And trade var emailAddress = "[email protected]";

for var emailAddress = $_POST["nomeDaVariavel"];

  • The problem is that on account of the action=""I would be redirected.

  • Redirect it to the page that has the code then redirect inside the code redirects back.

0


It’s simple, just put in your input a function onChange. It will be executed every time your input changes.

You can do it this way:

<input style="color: #ffffff;" onchange="handleEmailChange(this.value)" ng-model="user.email" type="email" placeholder="E-mail">

and in your script add the following javascript function:

function handleEmailChange(email){ emailAddress = email }

  • this script would have to be inside the function var auth = firebase.auth();&#xA;var emailAddress = "[email protected]";&#xA;&#xA;auth.sendPasswordResetEmail(emailAddress).then(function() {&#xA; // Email sent.&#xA;}).catch(function(error) {&#xA; // An error happened.&#xA;}); ???

  • Worked!!! function handleEmailChange(email){&#xA;var auth = firebase.auth();&#xA;emailAddress = email&#xA;auth.sendPasswordResetEmail(emailAddress).then(function() {&#xA;}).catch(function(error) {&#xA;});&#xA;};

Browser other questions tagged

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