如何根据表中的数据自动填写表单填充?

时间:2014-09-04 17:56:10

标签: forms coldfusion

我有一个表格,数据正在提交给表格。

使用列' month_date_show'我想自动填写表格 如果该日期存在于表中的列中,因为它只会每月提交一次。 如果表中存在日期,则用户将能够编辑这些结果(如果不存在) 然后无需自动填充用户将提交该月的新结果。

不确定这是否必须使用ajax或java脚本才能实现。 现在我对表单中的值进行了硬编码,但我想让它变得动态。

<cfquery datasource ="intranet" name="GetSummary">
            SELECT * from cse_result_summary    
        </cfquery>

<form method="post" name="myform" action="cse_execoffice_datepicker_test.cfm" onsubmit="return validateForm()">     
                    <table >
                    <tr>
                        <td>    
                        <input type="text" id="dpMonthYear"  NAME="month_date_show" value="9/2014" style="width:80px;" />
                        </td>
                    <td>
                        &nbsp;<img alt="Month/Year Picker" onclick="showCalendarControl('dpMonthYear');" 
                        src="pictures/datepicker.gif" />
                    </td>
                    </tr>
                    </table>
            <table >
            <tbody>     
                <tr>
                    <td>  Rising Star Award Winner:</td>
                    <td><input type="text" name="risingstar" size="50" class="get_branches_departments_displaynum" value="john"></td>       
                </tr>
                <tr>
                    <td>Department Average:</td>
                    <td><input type="text" name="risingstar_ave" size="8" class="get_branches_departments_displaynum" value="5"></td>
                </tr>

                    <tr>
                    <td>  Rising Star Award Winner runner-up:</td>
                    <td><input type="text" name="risingstar_runner" size="50" class="get_branches_departments_displaynum" value="joe"></td>

                </tr>
            </tbody>
            </table>

            <p><input type="submit" name="Submit" value="Submit"></p>
            </form>

2 个答案:

答案 0 :(得分:0)

好吧,如果您实际存储提交的表单的月份和年份,并假设用户正在提交当前月份和当前年份的表单(即现在是2014年9月,用户将提交表单以便09 / 2014但不提交任何其他表格的表格,例如08/2014),然后在用户到达您的页面时,您已经知道是否需要通过搜索数据库来获得新表格。

然后,您可以相应地填充表单。

答案 1 :(得分:0)

这取决于。如果您不关心用户是否刷新页面,只需提交表单onChange,运行查询以选择该日期的信息

SELECT winner, average, runup 
FROM tablename 
WHERE datecol = <cfqueryparam type=<whatevertypeappropriate> value="#val_name#">

在您的表单中,只需动态分配字段值。

<input type="text" name="winner" value="#queryname.winner#">

如果您不希望他们重新提交表单,我认为必须有某种约束力。