我有一个JS函数,它根据用户从下拉列表中选择的内容创建一个变量。我需要在我的CF代码上使用该JS变量,以便能够在提交表单以外的操作上使用它。
这是我的JS功能
function handleProcedureChange(procedureid,recID)
{
procedureid= document.form1.procedure.value;
recID = document.form1.recID.value;
state = document.form1.state.value;
state = state.trim();
city = document.form1.city.value;
city = city.trim();
var url ="../../../../cf_modules/components/customDescriptions.cfc?method=procedureDescription&";
url=url+"ProcedureID="+procedureid+"&recID=" + recID + "&state=" + state + "&city="+city;
$.get(url, function(procedureResult) {
procedureResult = procedureResult.replace(/^"+|"+$/g, "");
$("#procedureDescription").text(procedureResult);
});
}
这是我的表格
<select name="procedure" onChange="handleProcedureChange();">
<option value="">Select Procedure</option>
<cfloop query="procedures">
<option value="#procedureId#">#procedureName#</option>
</cfloop>
</select>
<textarea name="procedureDescription" id="procedureDescription" cols="80" rows="6"></textarea><br />
我需要在此链接上使用 url2 变量来控制几个服务器端函数
这些是链接序列
<cfoutput>[<a href="cityEdit.cfm?recID=#recID#&delete1=#recID#&state=#state#&city=#city.getCity()#&procedureid=#procedure#">delete</a>]</cfoutput>
<cfif delete1 neq "">
Are you sure?
<cfoutput> [ <a href="cityEdit.cfm?recID=#recID#&delete1=#delete1#&delete2=#delete1#&procedureid=#procedure#&state=#state#&city=#city.getCity()#">Yes</a> | <a href="cityEdit.cfm?recID=#recID#">No</a>]</cfoutput>
</cfif>
这些是上述链接控制的功能:
<cfparam name="delete1" default="">
<cfparam name="delete2" default="">
<cfif delete1 neq "">
<cfquery name="procFinder" datasource="#ds#">
select * from psp_customDescriptions where recID = '#delete1#'
and procedureID = '#procedure#' and city = '#city#' and state='#state#'
</cfquery>
</cfif>
<cfif delete2 neq "">
<cfquery name="deletepractice" datasource="#ds#">
delete from psp_customDescriptions where recID = '#delete2#'
and procedureID = '#procedure#' and city = '#city#' and state='#state#'
</cfquery>
<cflocation url="cityEdit.cfm?recID=#recID#" addtoken="no">
</cfif>
答案 0 :(得分:4)
如果在单击链接时移动逻辑运行怎么样?您还可以考虑使用jQuery之类的东西来获取值并设置事件处理程序。如上所述,您应该考虑使用帖子来修改/删除数据。
<script>
function handleDeleteLink()
{
procedureid= document.form1.procedure.value;
recID = document.form1.recID.value;
state = document.form1.state.value;
state = state.trim();
city = document.form1.city.value;
city = city.trim();
var url2 ="ProcedureID="+procedureid+"&recID=" + recID + "&state=" + state + "&city="+city;
document.deleteLink.href="cityEdit.cfm?"+url2;
}
</script>
<a id="deleteLink" href="#" onclick="">Delete</a>
答案 1 :(得分:1)
我不确定你的问题。表面上看似很明显。如果有人点击上面的链接,那就是:
cityEdit.cfm?recid=123&delete1=123&procedureid=345....
变量将在“URL”范围内传递给ColdFusion。所以你将拥有:
<Cfoutput>
#url.recid#
#url.delete1#
#url.procedureID#
</cfoutput>
这会回答你的问题吗?
如果您的问题是关于JS方面,那么您需要一个链接的功能。你可以添加一个监听器或一个单击处理程序代替“cityedit.cfm”作为你的链接,这样当用户点击删除它就会触发你的JS功能。然后在JS函数内部创建您的URL并将document.href.location执行到'cityEdit.cfm?' + url2;
是你的意思吗?
仅供参考 - 备考您应该在POST中更新数据库中的数据 - 特别是“删除”。它更加安全(并符合W3C)。
答案 2 :(得分:0)
我唯一需要的就是将这一行代码添加到我的JS函数中
$("#deleteProc1").html('<a href="cityEdit.cfm?recID='+recID+'&delete1='+recID+'&delete2='+recID+'&state='+state+'&city='+city+'&procedureid='+procedureid+"\">Delete</a>");
此链接可帮助我访问我的CF功能并删除我从下拉列表中选择的程序。
感谢所有评论我的问题