JavaScript:将HTML表输入字段数据推送到firebase数据库

时间:2018-02-23 07:43:50

标签: javascript html firebase firebase-realtime-database

我的表格上方和下方都有一些输入字段,而表格本身有输入字段。我需要做的是将所有这些数据保存在一个唯一的密钥下。 我的HTML代码

<table id="dataEntryTable" class="full">
    <thead>
        <tr>
            <th>[-]</th>
            <th>Item Code</th>
            <th>Product Name</th>
            <th>Qantity</th>
            <th>Unit Price</th>
            <th>Item Total</th>
        </tr>
    </thead>
        <tr>
            <td><input type="checkbox" id="checkBox0" name="chk"></td>
            <td><input type="text" id="itemCode1" class="dbData" placeholder="Enter Value"></td>
            <td><input type="text" id="productName1"class="dbData" placeholder="Enter Value"/></td>
            <td><input type="number" id="quantity1" min="1" value = "1" class="dbData"/></td>
            <td><input type="number" id="unitPrice1" min="0" value="0" step=".01" class="dbData" onblur="calculateItemTotal(1)"/></td>
            <td><input type="number" id="totalItem1" value="0" step=".01" class="total" readonly/></td>
        </tr>
</table>
<input type="button" class="btn" value="REMOVE ITEM" onclick="deleteRow('dataEntryTable')"/>
<input type="button" class="btn" value="ADD ITEM" onclick="addRow('dataEntryTable')"/>

从输入标记调用的所有函数都将值返回到fields.My表是动态的(用于添加和删除行的按钮)。而且我不关心它只是用于删除行操作的复选框。 这是JS代码

function submitData(e){
e.preventDefault();
uniqueBillGenerator();
//variables for getting all values 
var receiptDate = document.getElementById('date').innerHTML;
var receiptTime = document.getElementById('time').innerHTML;
var receiptBillNo = getInputValues('billNo');
var receiptCompName = getInputValues('companyName');
var receiptEmail = getInputValues('email');
var receiptPhone = getInputValues('phone');
var tableId = document.getElementById('dataEntryTable');
var discount = getInputValues('Discount');
var total = getInputValues('sumTotal');
var rowCount = tableId.rows.length;
var columns = tableId.rows[0].cells.length;

var newDataref = databaseRef.push();

newDataref.set({
    date: receiptDate,
    time: receiptTime,
    billNo: receiptBillNo,
    company: receiptCompName,
    email: receiptEmail,
    phone: receiptPhone,
    discount: discount,
    total:total

}); 
for(var i = 1; i < rowCount; i++){
    for(var j = 1; j < columns ; j++){
        //HOW TO DO PUSH THIS DATA TO FIREBASE UNDER SAME KEY
    }
}
}
function getInputValues(id){
    return document.getElementById(id).value;
}

提前致谢。

0 个答案:

没有答案