I have a select box labeled ‘campaign_value’ with dollar values in it. They look like this ($1, $2, $3, …). I have another select box that needs to get the updated value from ‘campaign_value’ when it is changed. Below is what I have so far…
HTML
<select id="campaign_value" name="campaign_value">
<option value="1">$1</option>
<option value="2">$2</option>
<option value="3">$3</option>
</select>
<select id="campaign_subject" name="campaign_subject">
<option value="You received $1 for food!">You received $1 for food!</option>
</select>
JS
$('#campaign_value').change(function(){
var replacement = $(this).val();
var regex = /\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/;
$('#campaign_subject option').each(function() {
this.text = this.text.replace(regex, replacement);
this.value = this.value.replace(regex, replacement);
});
});
What am I missing? Is my regex set correctly for dollar amounts?
Something like this:
Simple regex, nothing special.