2

我在coldfusion页面中有一个表格。点击插入表格的保存按钮后,我需要在选择框中使用表格的新值重新加载页面。虽然提交后页面刷新,但我无法在下拉列表中看到新插入的值。只有在手动刷新页面后我才能看到它。我有以下代码

  <script>
        function confirm_insert()
        {
            var ok = confirm("Are you sure you want to save the changes?");
            if (ok)
            {
                document.myform.submit();   
                return true;
            }
            else
            {
                return false;
            } 
        }
    </script>  

<form name="myform" action="bsc_lookup_number_add.cfm" method="post" >
           <td><input type="text" <cfif      isDefined('page.select_Main_Group')>value="#page.select_Main_Group#"</cfif>></td>
           <td><input type="text" <cfif isDefined('page.select_Sub_Group')>value="#page.select_Sub_Group#"</cfif>></td>
          <td><input name="newfirstchars" type="text" value="" maxlength="3"></td>

    <input type="submit" class="button" name="saverecord" id="saverecord"  style="width:100px" value="Save Record" onClick="return confirm_insert();">

            <cfquery name="first3" datasource="mbtran">
            select * from (
       select cast((substr(A.LABORLEVELNAME2, 1, 3)) as varchar2(5 byte)) first_3_pos
        from tkcsowner.VP_LABORACCOUNT a  
         <cfif isDefined('page.select_Sub_Group')>         
        where substr(A.LABORLEVELNAME1, 1, 5) || substr(A.LABORLEVELNAME2, 4, 2) = ('#page.select_Main_Group#' || '#page.select_Sub_Group#')
        </cfif>
        union
        select  A.FIRST_3_CHARS_IN_POSITION first_3_pos
        from kronos_if.FIRST_3_CHARS_IN_POSITION a    
         <cfif isDefined('page.select_Sub_Group')>     
        where A.DEPTID || A.UNION_CD = ('#page.select_Main_Group#' || '#page.select_Sub_Group#') 
        </cfif>
        )                          
        order by first_3_pos        
        </cfquery>

                <cfif isDefined('page.select_Sub_Group')>
                <td align="center">
                <select name="first3" id="first3" required="yes"        onchange="this.form.submit()">
             <option>Select</option>
             <cfloop query="first3">
                 <option value="#first_3_pos#" <cfif             isDefined('form.first3')><cfif form.first3 eq "#first_3_pos#">selected</cfif>       </cfif>>#first_3_pos#</option>
             </cfloop>
            </select></td>      

       </cfif>


         <cfif isdefined ("form.saverecord") and isdefined("form.newfirstchars")>

 <cfquery name="saverec" datasource="mbtran">

               insert INTO kronos_if.FIRST_3_CHARS_IN_POSITION
              (deptid,union_cd, first_3_chars_in_position,effdt)
                      values('#page.select_Main_Group#','#page.select_Sub_Group#','#FORM.newfirstchars#',sysdate)

</cfquery>               


        </cfif>

</form>

请指教。谢谢

截屏

4

1 回答 1

7

插入记录的查询位于用于填充下拉列表的查询之后。您需要移动此代码

<cfif isdefined ("form.saverecord") and isdefined("form.newfirstchars")>

<cfquery name="saverec" datasource="mbtran">
    insert INTO kronos_if.FIRST_3_CHARS_IN_POSITION
    (deptid,union_cd, first_3_chars_in_position,effdt)
    values ('#page.select_Main_Group#','#page.select_Sub_Group#','#FORM.newfirstchars#',sysdate)

</cfquery>               


</cfif>

在选择查询之上。

您还想研究使用 cfqueryparam - http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f6f.html

于 2013-01-14T23:30:03.407 回答