I have a table which contains three columns like this:
Amount | Upper banding | Lower banding
Each cell in the various columns has a css class applied (so cells in the 'amount' column have the class 'amount' and so on).
<table>
<tbody>
<tr>
<th class="amount">Amount</th>
<th class="upperBand">Upper banding</th>
<th class="lowerBand">Lower banding</th>
</tr>
<td>
<td class="amount">Amount</td>
<td class="upperBand">Upper banding</td>
<td class="lowerBand">Lower banding</td>
</tr>
...
</tbody>
</table>
The values for these columns are drawn from a database: wherever an exact amount is contained in the database the cell in the 'amount' column is populated, whenever a upper band is available the cell in the 'upper banding' column is populated, and so on. (A general rule-of-thumb is that whenever an exact amount is available no bands will be present, so if 'amount' is populated the other two cells will always be blank, i.e. contain a non-breaking space.)
I want to combine the upper and lower banding cells into the 'amount' cell, in the following way:
- if the 'amount' cell is populated, leave it as it is
- if both the 'upper banding' and 'lower banding' cells are populated, the 'amount' cell should read "[upper banding value]-[lower banding value]"
- if only the 'upper banding' cell is populated, the 'amount' cell should read "Up to [upper banding value]"
- if only the 'lower banding' cell is populated, the 'amount' cell should read "At least [lower banding value]"
- if all three cells contain non-breaking spaces, leave the 'amount' cell as it is
Can anyone tell me how to accomplish this with JQuery? I gather it'll require a series of 'if' statements, but my meager JQ skills ain't up to the task.
EDIT
It's probably worthwhile pointing out that I've attempted to do this several different ways, none of which have worked. I'd be happy simply to be pointed in the right direction, as in being told what JQ functions to make use of - I don't expect anyone to write my code for me.