Populate fields based on dropdown selection
by katalin_2003
HTML
<form action="/revenue_lines/lock" id="lockLockForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST">
</div> <span>Between</span>
<input name="data[RevenueLine][date1]" class="input datepicker hasDatepicker" type="text" id="RevenueLineDate1"> and
<input name="data[RevenueLine][date2]" class="input datepicker hasDatepicker" type="text" id="RevenueLineDate2">
<input class="submit_black gradient" style="display: inline;" type="submit" value="Submit">
<label for="FinancialMonthSelector"> ...or select financial month to auto-populate </label>
<select name="data[FinancialMonth][selector]" class="chzn-select med chzn-done" id="FinancialMonthSelector">
<option value="-------_*******"></option>
<option value="foo_bar">foo bar</option>
<option value="22JUN2013_26JUL2013">2013 - July</option>
<option value="27JUL2013_30AUG2013">2013 - August</option>
</select>
</form>
JavaScript
$('#FinancialMonthSelector').on('change', function () {
var val = this.value;
var parts = val.split("_");
$('#RevenueLineDate1').val(parts[0]);
$('#RevenueLineDate2').val(parts[1]);
});