gpt4 book ai didi

javascript - onsubmit 需要重新加载页面

转载 作者:行者123 更新时间:2023-12-03 16:39:53 26 4
gpt4 key购买 nike

我在 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>

请指教。谢谢

Screenshot

最佳答案

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

<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

关于javascript - onsubmit 需要重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14327616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com