I am working on a website which is constructed on mvc framework.
The problem isn’t related to mvc or web development but rather I feel it is a general programming issue. So I have a if and else block which is behaving unexpectedly.
Code:
class table {
constructor(datatypes, header, data, customfunctionsindex, customfunctionstype, customfunctions) {
this.datatypes = datatypes;
this.header = header;
this.data = data;
this.customfunctions = customfunctions;
this.customfunctionsindex = customfunctionsindex;
this.customfunctionstype = customfunctionstype;
}
}
var data= new table(["label", "label", "input", "input", "input", "label","select", "button"],
["Saletype", "Service", "Quantity", "Discount", "GST", "Amount", "Employee", "Remove"], [],
[2, 3, 4, 6], [function () {}, "null", "null", "null"],
["onchange", "onchange", "onchange", "onclick"]);
for (var i = 0; i < data.header.length; i++) {
var cell = row.insertCell(i);
var element = document.createElement(data.datatypes[i]);
element.id = data.header[i] + (table.rows.length - 1);
if (data.datatypes[i] == "label") {
console.log(data.datatypes[i]+i);
element.innerHTML = data.data[i];
element.style.backgroundColor = "rgb(134 198 244)";
element.style.color = "white";
element.style.borderRadius = "0";
}
if (data.datatypes[i] == "input") {
console.log(data.datatypes[i]+i);
element.value = data.data[i];
element.style.backgroundColor = "rgb(134 198 244)";
element.style.color = "white";
element.style.borderRadius = "0";
}
if (data.datatypes[i] =="select")
{
console.log(data.datatypes[i]+i);
for (var i = 0; i < employees.length; i++) {
var option = document.createElement("option");
option.text = employees[i].name;
option.value = employees[i].name;
element.appendChild(option);
}
element.style.backgroundColor = "black";
element.style.borderRadius = "10px";
element.style.color = "white";
}
else {
console.log(data.datatypes[i]+i);
element.innerHTML = data.data[i];
element.style.backgroundColor = "red";
element.style.color = "black";
element.style.borderRadius = "0";
}}


