Recollective Object Iteration
by dixalex
HTML
<div style='display: none;'>
Education
<table class='recoEducation'>
<tbody>
<tr>
<td>Some High School or Less</td>
<td>1</td>
</tr>
<tr>
<td>High School Graduate</td>
<td>2</td>
</tr>
<tr>
<td>Some College</td>
<td>3</td>
</tr>
<tr>
<td>College Gradutate or more</td>
<td>4</td>
</tr>
<tr>
<td>Prefer not to answer</td>
<td>5</td>
</tr>
</tbody>
</table>
Ethnicity
<table class='recoEthnicity'>
<tbody>
<tr>
<td>Caucasian</td>
<td>1</td>
</tr>
<tr>
<td>Black or African American</td>
<td>2</td>
</tr>
<tr>
<td>Asian or Pacific Islander</td>
<td>3</td>
</tr>
<tr>
<td>Native American</td>
<td>4</td>
</tr>
<tr>
<td>Latin/Hispanic</td>
<td>5</td>
</tr>
<tr>
<td>Mixed</td>
<td>6</td>
</tr>
<tr>
<td>Other (specify)</td>
<td>7</td>
</tr>
<tr>
<td>Prefer not to answer</td>
<td>8</td>
</tr>
</tbody>
</table>
Income
<table class='recoIncome'>
<tbody>
<tr>
<td>Less than $30,000</td>
<td>1</td>
</tr>
<tr>
<td>$30,000 to just under $50,000</td>
<td>2</td>
</tr>
<tr>
<td>$50,000 to just under $75,000</td>
<td>3</td>
</tr>
...
CSS
table {
border: solid 1px #000;
border-collapse: collapse;
margin-bottom: 15px;
width: 250px;
}
td {
border: solid 1px #000;
min-width: 40px;
}
JavaScript
var recoEducation = {};
var recoEthnicity = {};
var recoIncome = {};
var recoState = {};
var eduString = "";
var ethString = "";
var inString = "";
var staString = "";
$('table.recoEducation tr').each(function() {
var cellOne = $(this).find('td:first');
var cellTwo = $(this).find('td:last');
recoEducation[cellTwo.html().toString()] = cellOne.html().toString();
});
$('table.recoEthnicity tr').each(function() {
var cellOne = $(this).find('td:first');
var cellTwo = $(this).find('td:last');
recoEthnicity[cellTwo.html().toString()] = cellOne.html().toString();
});
$('table.recoIncome tr').each(function() {
var cellOne = $(this).find('td:first');
var cellTwo = $(this).find('td:last');
recoIncome[cellTwo.html().toString()] = cellOne.html().toString();
});
$('table.recoState tr').each(function() {
var cellOne = $(this).find('td:first');
var cellTwo = $(this).find('td:last');
recoState[cellTwo.html().toString()] = cellOne.html().toString();
});
function educationMatch(educationString) {
var educationMatchIndex, objectLength = Object.getOwnPropertyNames(recoEducation).length;
for (x = 1, z = objectLength; x < z; x++) {
if (recoEducation[x].match(educationString)) {
educationMatchIndex = x;
}
}
return educationMatchIndex;
}
function ethnicityMatch(ethnicityString) {
var ethnicityMatchIndex, objectLength = Object.getOwnPropertyNames(recoEthnicity).length;
for (x = 1, z = objectLength; x < z; x++) {
if (recoEthnicity[x].match(ethnicityString)) {
ethnicityMatchIndex = x;
}
}
return ethnicitynMatchIndex;
}
function incomeMatch(incomeString) {
var incomeMatchIndex, objectLength = Object.getOwnPropertyNames(recoIncome).length;
for (x = 1, z = objectLength; x < z; x++) {
if (recoIncome[x].match(incomeString)) {
incomeMatchIndex = x;
}
}
return incomenMatchIndex;
}
function stateMatch(stateString)...