我有以下由 CakePHP 的表单助手生成的 HTML。在界面中,用户选择两个日期,然后在生成的 PHP 中使用这两个日期从 MySQL 中提取数据。我还为用户提供了“财务月份”,它们在 MySQL 中定义为预填充两个日期字段的快捷方式。但是,我完全不知道如何实现这一点,因为我的 jQuery/Javascript 知识非常有限。
我想要做什么:当用户从 SELECT 框中选择某些内容时,将 _ 之前的选项值拉入 date1,将 _ 之后的选项值拉入 date 2。
这可能吗?
编辑:这是 CakePHP 中产生表单的代码:
<script type="text/javascript" src="/js/revenuelines.js"></script>
<h1>Lock revenue</h1>
<div class="inner">
<p>Select two dates to lock revenue for the specified period.</p>
<?php
echo $this->Form->create('lock');
?>
<span>Between</span>
<?php
echo $this->Form->input('RevenueLine.date1', array('div' => false, 'class' => 'input datepicker', 'label' => false));
echo " and ";
echo $this->Form->input('RevenueLine.date2', array('div' => false, 'class' => 'input datepicker', 'label' => false));
echo $this->Form->submit('Submit', array('label' => false, 'div' => false, 'class' => 'submit_black gradient', 'style' => 'display: inline;'));
echo $this->Form->input('FinancialMonth.selector', array('label' => ' ...or select financial month to auto-populate ', 'div' => false, 'class' => 'input', 'options' => $months));
echo $this->Form->end();
?>
</div>
这是生成的实际 HTML:
<div id="content">
<script type="text/javascript" src="/js/revenuelines.js"></script>
<h1>Lock revenue</h1>
<div class="inner">
<p>Select two dates to lock revenue for the specified period.</p>
<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="input" id="FinancialMonthSelector">
<option value="22JUN2013_26JUL2013">2013 - July</option>
<option value="27JUL2013_30AUG2013">2013 - August</option>
</select></form></div>
</div>