I was wondeirng if there was a better way to do an if statement.
I am looping thorugh an array, and I want to check to see if the current value is equal to a certain string. Here is my code:
Currently it doesnt seem to work for 'Author' or 'Class'
Thanks!
I am looping thorugh an array, and I want to check to see if the current value is equal to a certain string. Here is my code:
Code:
var advancedSearchTable = document.createElement("table");
var labels = new Array('Modifier', 'Class', 'Title', 'Author', 'External');
for (var i = 0; i < labels.length; i++) {
// Create a table row
var row = advancedSearchTable.insertRow();
// This cell will hold the label
var label = row.insertCell();
// Style the label
label.style.fontSize = labelFontSize;
label.style.fontWeight = labelBoldness;
label.style.labelAlign = labelAlign;
label.style.padding = labelPadding;
label.innerHTML = labels[i];
// This cell will hold the form component
var field = row.insertCell();
field.id = 'advancedSearch' + labels[i];
field.style.textAlign = 'right';
if (labels[i] == ('Title' || 'Author')) {
// Create a text box
var formComponent = document.createElement("input");
formComponent.type = 'text';
} else if (labels[i] == ('Modifier' || 'Class')) {
// Create a text box
var formComponent = document.createElement("select");
} else {
// Create a text box
var formComponent = document.createElement("input");
formComponent.type = 'checkbox';
}
field.appendChild(formComponent);
}
Currently it doesnt seem to work for 'Author' or 'Class'
Thanks!