我試圖將文本中輸入的文本和從下拉菜單中選擇的選項存儲到Firebase。我已經將我的代碼鏈接到下面。上傳的文件正在保存,但所選文本和選項未保存到Firebase數據庫。任何幫助,將不勝感激。將文本和下拉選擇保存到Firebase
下面是javascript代碼:
/*jslint plusplus: true*/
var index = 0;
var Email = sessionStorage.getItem("email");
var EmailU = Email[index];
var uploader = document.getElementById("uploader");
var fileButton = document.getElementById("fileButton");
//Listen for file selection
fileButton.addEventListener('change', function(e) {
// Get File
var file = e.target.files[0];
//Create a storage ref
var storageRef = firebase.storage().ref(Email + file.name);
/** folder name will be email**/
//Upload file
var task = storageRef.put(file);
//Update progress bar
task.on('state_changed',
function progress(snapshot) {
var percentage = (snapshot.bytesTransferred/snapshot.totalBytes) * 100;
uploader.value = percentage;
},
function complete() {
sessionStorage.setItem(file.name);
});
});
}
//function to gets the value from the html and stores them into an array
function AddMed() {
'use strict';
//Create array of values from html
var database = firebase.database();
function writeUserData(userId, name, email, image) {
firebase.database().ref('users/' + EmailU).set({
MedName: document.getElementById("MTitle").value, // title of Med
description: document.getElementById("Adescription").value, //descripton of Med
Type: document.getElementById("TypeSelect").value, // Type
//Start: document.getElementById("AStart").value, //when does it start
//End: document.getElementById("AEnd").value //when does it end
});
index++;
}
}
的HTML代碼是這樣的:
<h1><b>Medicine Schedule</b></h1>
<!---------------------------------------------- START of Form ---------------------------------------------->
<div id="form">
<form>
Name of Medicine <input type="text" id="MTitle" size="50" name="MedicineTitle">
<br>
<br> Descritption:
<br> <textarea id="Adescription" rows="2" cols="50" name="AnnouncementDescription" placeholder="Provide a description of what the medicine is. "></textarea>
<br>
<br> Type: <select id="TypeSelect">
<option>Pill</option>
<option>Syrup</option>
<option>Drop</option>
<option>Cream</option>
</select>
<br>
<br> Start Date: <input type="date" id="AStart" placeholder="dd/mm/yyyy" name="MeetingTime">
<br>
<br> End Date: <input type="date" id="AEnd" placeholder="dd/mm/yyyy" name="MeetingTime">
<br>
<br>
</form>
</div>
<!------------------------------------ END of Medicine Form ------------------------------------------>
<div id="progress">
<progress value="0" max="100" id="uploader">0%</progress>
<input type="file" value="upload" id="fileButton" />
</div>
<br>
<br>
<button type="button" class="btn btn-success btn-md" onclick="AddMed()"> Submit Medicine</button>
at line類型:document.getElementById(「TypeSelect」).value(最後沒有逗號)。先解決這個問題。 – rattanak
你有什麼錯誤? – rattanak
已修復。我沒有得到任何錯誤,它只是不節省 –