I have a looping span element on my page that is generated based on the number of records in a database table. The appearance of the span can vary, displaying either one or multiple instances. Each span has the following structure:
<span class="add-on" id="goaltypeicon"></span>
Adjacent to the span, there is a dropdown menu that determines whether the span should show a $
sign or a %
sign based on the user's selection. Here is the dropdown menu:
<select onchange="selectSavingOption(this)" class="input-xxlarge" id="saving_options"
name="saving_options" style="width: 100%">
<option value="weekly_savings_amount"> Set Weekly Savings Amount</option>
<option value="weekly_savings_percent">Allocate % Of Weekly Savings</option>
</select>
Below is the JavaScript function that triggers when the dropdown menu selection changes:
function selectSavingOption(element) {
if (element.options[element.selectedIndex].value == 'weekly_savings_amount') {
alert('amount');
$("#goaltypeicon").html('$');
}if (element.options[element.selectedIndex].value == 'weekly_savings_percent') {
alert('percent');
$("#goaltypeicon").html('%');
}
}
While this solution works for the first occurrence of the span, it does not update all subsequent spans with the selected symbol ($
or %
). I am seeking assistance to ensure that each span reflects the correct symbol depending on the user's choice.
In summary, the value weekly_savings_amount
should display the $
symbol and the value weekly_savings_percent
should display the %
symbol.