Firebaseを使用してボタンをクリックすると、フォームの内容を実際にクリアするのに問題があります。私はちょうど1つのテキストフィールドを持っていることを持っている別のフォームにtype="reset"
を使用することができるよ、しかし、2番目の形式は2つのテキストフィールドを持って、私がしようとするときは、次のボタンをクリックするとフォームのリセット/クリア
function clearFields() {
document.getElementById(userCityEmail).value = "";
document.getElementById(cityTextField).value = "";
}
または私はちょうど使用して、この(何かを試してみてくださいリセット()):
function clearFields() {
document.getElementById(userCityEmail).reset();
document.getElementById(cityTextField).reset();
}
ページはリロードされますが、Firebaseには何も送信されません。上記の機能を使用せず、テキストをテキストフィールド内に残しておけば、コンテンツをFirebaseに送信します。どこが間違っていますか?前もって感謝します!
<form id="myform" method="post">
<input type="email" class="contactUsEmail" id="userCityEmail" placeholder="Enter email" name="contactUsEmail">
<input type="text" class="contactUsEmail" id="cityTextField" placeholder="City" name="contactUsCity">
<button type="submit" id="citySubmitButton" onclick="submitCityClick(); clearFields(); return false;" class="btn btn-primary contactUsButton">Submit</button>
</form>
Javascriptを::
var userCityEmail = document.getElementById('userCityEmail');
var cityTextField = document.getElementById('cityTextField');
var citySubmitButton = document.getElementById('citySubmitButton');
function submitCityClick() {
var firebaseRef = firebase.database().ref();
var userEmail = userCityEmail.value + " " + cityTextField.value;
firebaseRef.child("potentialCities").push().set(userEmail);
}
function clearFields() {
document.getElementById(userCityEmail).value = "";
document.getElementById(cityTextField).value = "";
}
あなたの 'clearFields()'呼び出しはまったく動作しますか? HTML要素が 'userCityEmail'と' cityTextField'の値として格納されていれば、document.getElementByIdを呼び出しています。 – imjared