How to get email field in tracking event jquery - javascript

Trying to fire a tracking use by email so have the following code
$('.form').submit(function() {
var email = $('#form-field').val();
theTracking('userEmail', 'email');
});
Why email veriable not returning the email value?

Try this code. if not working show me what is in your console.
$('.form').submit(() => {
const email = $('#form-field').val();
console.log('email:', email);
console.log('form-field:', $('#form-field'));
theTracking('userEmail', email);
});

Related

Console says onsubmit function doesn't exist for register form, even though it clearly does

So I have a register form, as thus:
<form name="register" action="" method="POST" onsubmit="register()" autocomplete="off">
...
</form>
And I know that every child of this form is functioning.
Then, below in a <script> tag I have my main function which is called when the above form is submitted. And I know that everything outside of the register function is running. However, when I input random values into each field of my form, and press submit, the console shows that the register() function called in the onsubmit attribute of my form does not exist. I can't seem to find the problem here:
//Global Vars
var firebaseConfig = { ...
};
firebase.initializeApp(firebaseConfig);
var db = firebase.firestore();
var registerButton = document.querySelector("#registerButton");
//Main Register Function
function register() {
event.preventDefault();
//Locally Global Variables
var fullName = document.forms["register"]["fullName"].value;
var username = document.forms["register"]["username"].value.toLowerCase();
//The MD5 is a way to hash the password, that way the real password is safe and only the hash is used
var password = md5(document.forms["register"]["password"].value);
var serviceProvider = document.forms["register"]["serviceProvider"].value;
//Simple If Statement that adds appropriate email suffix based on Service Provider
if (serviceProvider === "Verizon") {
serviceProvider = "#vtext.com";
} else if (serviceProvider === "ATT") {
serviceProvider = "#txt.att.net";
} else if (serviceProvider === "TMobile") {
serviceProvider = "#tmomail.net";
} else if (serviceProvider === "Sprint") {
serviceProvider = "#messaging.sprintpcs.com";
}
var phoneNumber = document.forms["register"]["phoneNumber"].value + serviceProvider;
var emailAddress = document.forms["register"]["emailAddress"].value;
//Checks The Database If The Username Is Already Taken Or Not
db.collection("Users").where("username", "==", username).get()
.then(function(querySnapshot) {
//Checks Each Individual Result -- If there are no results, than this code will not run
try {
querySnapshot.forEach(function(doc) {
//If any result exists, stop here
if (doc.data()) {
alert("I'm sorry but this username is already taken!! Please Try Another One");
throw "Error";
}
});
} catch (error) {
if (error === "Error") {
return;
}
}
//If not
//Add All Of The User Info To The Database
db.collection("Users").doc(username).set({
fullName: fullName,
username: username,
password: password,
phoneNumber: phoneNumber,
emailAddress: emailAddress,
chatsInvolvedIn: []
})
.then(function() {
//If it succeeds, give user the heads up and then take them to their new homepage
alert("Your account under the username " + username + " has been sucessfully created. You will now be redirected to your homepage.");
//Place Code Underneath to Handle Keeping user Logged In For Present and Future Visits, along with redirecting to a homepage
//Code Goes Here
db.collection("Users").doc(username).get().then(function(doc) {
if (doc.exists) {
localStorage.setItem("loggedIn", JSON.stringify(doc.data()));
}
alert(localStorage.getItem("loggedIn"));
//window.location.replace("index.html");
});
})
.catch(function(error) {
//If it fails, tell user to try again later (we don't care about the error message during production, because it is unlikely after our many tests)
alert("I'm sorry but your account was not successfully created due to an unexpected error. Please try again later.");
});
})
.catch(function(error) {
//If checking the database originally for duplicate usernames fails, then give the user the same warning as above
alert("I'm sorry but your account was not successfully created due to an unexpected error. Please try again later.");
});
}
I know that my programming practices above aren't the best. if you could help me out, that would be great, thank you!

How to create a new user in firebase using javascript

I am making a web app. For now i am able to enter and retrieve data in firebase. I want to enter the email and password details of my form to the "Users" tab under "authentication" of firebase and then i am trying to login.
The following is my code to enter my data to user.
function submitForm(e) {
e.preventDefault();
//get values
var name = getInputVal('name');
var address = getInputVal('address');
var email = getInputVal('email');
var phone = getInputVal('phone');
var password = getInputVal('password');
enterUser(email, password);
saveMessage(name, address, email, phone, password);
//show alert
document.querySelector('.alert').style.display = 'block';
//hide alert after three secs
setTimeout(function() {
document.querySelector('.alert').style.display = 'none';
}, 3000);
document.getElementById('contactform').reset();
}
function enterUser(name, password) {
if ((name) && (password)) {
firebase.auth().createUserWithEmailAndPassword(name,
password).then(function(user) {
// Enters the new user fields
console.log(user.email);
// ...
});
}
}
The first function "submitform" works when i click a submit button on my DOM. This function stores all the data into a collection "messages" in firebase. After that through my "enterUser" function i am trying to create the user with email and password entered in the "submitForm" and enter it into the "users authentication" of firebase. The problem is, it is not creating any user as shown by the figure below.
But the data is being stored in the "messages" collection in firebase.(shown below)
My question: How to save the email and password in the "users-authentication"?
First make sure you have sign-in method enabled

Customize Forgot Password Email .Meteorjs

This function below works just fine. But How do I change the sender parameters of the forgot password email.
sendForgotpasswordmail() {
let options = {};
options.email = this.state.email;
Accounts.forgotPassword(options, function(error){
if (error) {
console.log(error);
}else{
alert('Check your mailbox!');
}
});
}
Whenever I send that I get the sender as From: "Meteor Accounts" <no-reply#meteor.com>
and that is what I want to change
You should be able to change this by adding the following:
Accounts.emailTemplates.resetPassword.from = function () {
// Overrides value set in Accounts.emailTemplates.from when resetting passwords
return "AwesomeSite Password Reset <no-reply#example.com>";
};
Further explained in the docs:
http://docs.meteor.com/api/passwords.html#Accounts-emailTemplates

"Event is not defined" error message is showing when I try to open email client using dblclick()

I have 2 email input fields with a class name of send_email. I want to show a email client when the user double clicks on an email field. To do that I am using the following jQuery code but it's showing an error message:
event is not defined
$(document).ready(function(){
$('input.send_mail').dblclick(function() {
event.preventDefault();
var email = $(this).val();
var subject = '';
window.location = 'mailto:' + email + '?subject=' + subject;
});
});
In your dblclick code you use event.preventDefault(), yet haven't set the event property. Try this:
$('input.send_mail').dblclick(function(event) { // < 'event' here
event.preventDefault();
// your code...
}):

Form submit add domain to username field if missing

I have a login form that includes a username and password field.
Users will be able to login using:
Domain\username
And
Username#domain.org.uk
However many users attempt to login using just 'username'
I want to help users by adding domain\ or #domain.org.uk to there username when they enter just 'username', when they click the login button I want to add the domain part of the username.
How can I do this in pure JavaScript?
function insertDomain (){
var txtBox = document.getElementById('Your_Textbox');
if(txtBox.value.indexOf("#") == -1)
{
txtBox.value += "#domain.org.uk";
}
}
On Submit: http://alexking.org/blog/2003/10/01/javascript-onsubmit-handler
Something along the lines of
var username = document.getElementById('username')
if(username.indexOf('#') < 0){
username = usename + '#domain.org.uk';
}

Categories