1

I am having some trouble using a jquery listener on a submit button to get it to run a function on the form's data. I have this html 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="[email protected]"><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>

And I'm using this jQuery listener in my CSS stylesheet:

$('#patientcreatebutton').click(
    createpatient($('#form1'));
);

Here's the javascript function it's calling.

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");

};

For some reason, I'm not even getting the first console message from the javascript function. Am I hooking up the jQuery listener wrong?

3
  • 3
    And I'm using this jQuery listener in my CSS stylesheet: <<< really, in your stylesheet? Commented Dec 19, 2014 at 19:08
  • That's how I learned (very recently learned) to put it. Is there a more efficient/standard location? Commented Dec 19, 2014 at 19:21
  • I have moved my jquery listeners, but the code still does not execute. Commented Dec 19, 2014 at 19:30

1 Answer 1

1

You need to wrap your function inside lambda, like this:

$('#patientcreatebutton').click(function() {
  createpatient($('#form1'));
});
Sign up to request clarification or add additional context in comments.

3 Comments

are you sure you initialized the click() handler inside document ready function?
Oh. I don't think I did that. I'm mostly learning as I make it. How would initializing the handler look?
You need to have $(document).ready() somewhere in your code and execute all javascript inside it. $(document).ready(function() { //all your javascript code goes here. });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.