I'm encountering an issue with implementing a jQuery listener on a submit button to execute a function on the form's data. Below is the HTML code for my form:
<div class = "window" id="patientsignup">
<h1>Add New Patient</h1>
<form id = "form1">
<label>First name: </label> <input type="text" name="FirstName" value="First"><br>
<label>Last name: </label><input type="text" name="LastName" value="Last"><br>
<label>Email: </label><input type="text" name="email" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="462c292e2822292306232b272f2a6825292b">[email protected]</a>"><br>
<label>Phone Number: </label><input type="text" name="phonenumber" value="Phone Number"><br>
<input type="button" id="patientcreatebutton" name="createbutton" value="Create Patient">
</form>
</div>
Additionally, this is the jQuery listener used in my CSS stylesheet:
$('#patientcreatebutton').click(
createpatient($('#form1'));
);
Here's the javaScript function that is being called.
function createpatient(form) {
console.log("Begin creating patient");
var currentUser = Parse.User.current();
var username= form.email.value;
var email= form.email.value;
var doctorIdentifier= currentUser.id;
randkey = makeid();
var password= randkey;
var doctorCode= randkey;
var phoneNumberForPatient= form.phonenumber.value;
var doctorsUserName= currentUser.username;
Parse.Cloud.run("inviteUser", {"email": email, "password": password, "doctorCode": password, "phoneNumberForPatient": phoneNumberForPatient, "doctorUserName": doctorsUserName, "doctorIdentifier": doctorIdentifier}, {
success: function(result) {
console.log("Successfully invited user!");
console.log("Please have your patient log in with the following code: " + doctorCode);
},
error: function(error) {
console.log("There has been an error.");
console.log(error);
}
});
createpatientwindow.style.visibility = "hidden";
$(generatecalorieswindow).addClass("slideLeft");
};
However, I am not receiving the initial console message from the javascript function. Have I connected the jQuery listener incorrectly?