Reputation: 133
I've got a JavaScript function that's supposed to be executed when an HTML button is clicked. The HTML for the form is
<form id="inputData">
Email:<br>
<input id="email" type="email" name="email"><br>
Username:<br>
<input id="username" type="text" name="username"><br>
Password:<br>
<input id="password" type="password" name="password"><br>
<input id="submit" type="submit" value="submit" onClick="getData()">
</form>
The related js code is
<script type="text/javascript">
function getData() {
var input = document.getElementById("inputData");
var email = input[0].value;
var user = input[1].value;
var pass = input[2].value;
sendData(user,email,pass)
}
function sendData(user,email,pass) {
var fireRef = firebase.database().ref("users/" + user);
fireRef.set({
emailAddress: email,
password: pass,
});
}
</script>
In debugger mode, the function gets executed when the submit
button is clicked, and there are no errors, all of the form data is properly collected, yet the data never gets sent to the Firebase database. However, if i call the sendData
function through the console and manually provide data in the arguments, it works perfectly. Can anyone think of why this might be happening?
Upvotes: 0
Views: 262
Reputation:
onClick
event isn't triggering
try
<form id="inputData" onsubmit="getData()">
Email:<br>
<input id="email" type="email" name="email"><br>
Username:<br>
<input id="username" type="text" name="username"><br>
Password:<br>
<input id="password" type="password" name="password"><br>
<input id="submit" type="submit" value="submit">
</form>
Upvotes: 2