I wanted to create a button that shows the pop up to show the user that the OTP code has sent to their mobile phone, and also be able to link it to another "Verify OTP Code" page to let the user type in the verification code that is sent to their mobile phone. How do I create a button that calls two functions when it is being clicked? I tried the code below and it is not working at all. Can someone provide me an answer on how to create a button that calls two actions when it is clicked?
This my button in the HTML code:
<div class="col-md-12">
<div class="form-group">
<input type="text" id="number" name="phone" class="form-control" placeholder="Phone Number" required>
<br>
<div id="recaptcha-container"></div>
<button id="verify"class="block"type="button" onclick="one(); phoneAuth();">
Send Verification Code
</button>
</div>
</div>
This is my JavaScript code:
window.onload = function () {
render();
};
function render() {
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container');
recaptchaVerifier.render();
}
function one() {
window.location.href = 'insert.php';
}
function phoneAuth() {
//get the number
var number=document.getElementById('number').value;
//phone number authentication function of firebase
//it takes two parameter first one is number,,,second one is recaptcha
firebase
.auth()
.signInWithPhoneNumber( number, window.recaptchaVerifier )
.then(
function ( confirmationResult ) {
//s is in lowercase
window.confirmationResult = confirmationResult;
coderesult = confirmationResult;
console.log(coderesult);
alert("Message sent");
}
)
.catch(
function (error) {
alert(error.message);
}
);
}
function codeverify() {
var code = document.getElementById('verificationCode').value;
coderesult
.confirm(code)
.then(
function ( result ) {
alert("Phone Number Verified");
var user=result.user;
console.log(user);
}
)
.catch(
function ( error ) {
alert(error.message);
}
);
}