gpt4 book ai didi

javascript - 以 coldfusion 形式提交时未选中复选框

转载 作者:行者123 更新时间:2023-11-30 06:31:40 25 4
gpt4 key购买 nike

我再次在此处发布此问题,因为我需要上一个问题的进一步帮助 Checkbox in a ColdFusion form

<form action="view_emp_qual.cfm?show=yes" id="Myform" method="post" name="myform">

<table id="tab1" align="center">
<tr>
<td>
<input type="checkbox" onclick="return callme();"
<cfif structKeyExists(form, 'chkbox3')>
checked="checked"
</cfif>
name="chkbox3" id="chkbox3">
<strong>All Employees</strong>

<input type="checkbox" onclick="return callme1();"
<cfif NOT structKeyExists(form, 'fieldnames') OR structKeyExists(form, 'chkbox1') OR (structKeyExists(form, 'fieldnames') and structKeyExists(form, 'chkbox1'))>
checked="checked"
</cfif>
name="chkbox1" id="chkbox1" />
<strong>Agreement Only</strong>

<input type="checkbox" onclick="return callme1();"
<cfif NOT structKeyExists(form, 'fieldnames') OR structKeyExists(form, 'chkbox2') OR (structKeyExists(form, 'fieldnames') and structKeyExists(form, 'chkbox2'))>
checked="checked"
</cfif>
name="chkbox2" id="chkbox2"/>
<strong>Active Employees</strong>

<td>
<input type="Submit" name="submitnow" value="View Selected" class="button1">
<td>
<input type="button" name="Back" value="Back to Previous Menu" onclick="javascript:document.location.href('qualyrs_maint.cfm');" class="button1">
</tr>
</table>
</form>

我现在有 3 个复选框,其中最后两个需要在页面加载和显示查询结果时选中。并且当最后两个未选中时必须选中第一个并相应地显示查询结果。

现在我在页面上有一个排序栏功能。像这样

<cfif isdefined("form.order_by") and form.order_by eq "EMPLID">
background-color:##
<cfif sort_order eq "asc">
666666
<cfelse>
000000
</cfif>
</cfif>
;"
onClick="sortBy('EMPLID');Sorting.style.display='block';">
EMPLID
<cfif isdefined("form.sort_order") and isdefined("form.order_by") and ucase(form.sort_order) eq 'ASC' and ucase(form.order_by) eq 'EMPLID'>
<img src="images/desc.jpg">
<cfelseif isdefined("form.sort_order") and isdefined("form.order_by") and ucase(form.sort_order) eq 'DESC' and ucase(form.order_by) eq 'EMPLID'>
<img src="images/asc.jpg">
</cfif>

这是 JS

<script language="Javascript">
function sortBy(order) {
foo = document.getElementById("order_by_id");
bar = document.getElementById("sort_order_id");
<!---if (foo.value == order) {
//same thing again, so flip the sort
if (bar.value == 'DESC'){
bar.value = 'ASC';
}
else{
bar.value = 'DESC';}
//bar.value = bar.value == "ASC" ? "DESC" : "ASC";
} else {
//new sort order, so make it ASC
bar.value = "ASC";
}--->
foo.value = order;
sort.submit();
}
</script>

<cfscript>
if(IsDefined('form.sort_order'))
{
if(form.sort_order IS 'ASC')
sort_order_value = 'DESC';
else
sort_order_value = 'ASC';
}
else
sort_order_value = 'ASC';
</cfscript>

<form action="view_emp_qual.cfm?show=yes" method="post" name="sort">
<cfoutput>
<cfparam name="order_by" default="">
<input type="hidden" name="order_by" id="order_by_id" value="#order_by#">
<input type="hidden" name="sort_order" id="sort_order_id" value="#sort_order_value#">

<cfif Isdefined("Form.fieldnames")>
<cfloop index="fieldname" list=#form.fieldnames#>
<cfset fieldvalue = Evaluate("form." & #fieldname#)>
<cfif not ("order_by,sort_order") contains fieldname>
<input type="hidden" name=##fieldname## value="#fieldvalue#">
</cfif>
</cfloop>
</cfif>
</cfoutput>
</form>

现在我的一切都按我的需要工作了,除了,在页面加载时,当最后两个复选框被选中时,我点击了排序列图标,然后第一个复选框被选中。请告知我的代码哪里出错了。谢谢

最佳答案

你的问题/方法非常困惑,我花了很多时间试图理解你在做什么。我注意到错误但无法修复您的代码,因为很难阅读您所做的一些事情,我在下面创建了类似的东西 - 匆忙。它使用相同的形式进行排序和展示,并允许您使用其他几个“顺序”键(empid ...)。我还对其进行了评论,以便您了解我在每一点上所做的事情。单击订单链接会重新提交表单,传递当前表单中的相同值,并且在处理表单提交时,您可以根据需要使用 sort_order_value 和 order_by_value。

<!--- initialized needed variables --->
<cfscript>
isPost = structKeyExists(form, 'fieldnames'); //if form was submitted
chkbox1Selected = structKeyExists(form, 'chkbox1'); //if chkbox1 is selected
chkbox2Selected = structKeyExists(form, 'chkbox2'); //if chkbox2 is selected
chkbox3Selected = structKeyExists(form, 'chkbox3'); //if chkbox3 is selected
param name="order_by_value" default="EMPLID"; //default order_by_value is EMPLID
if(structKeyExists(form, 'sort_order') AND form.sort_order IS 'ASC') //if sort order was specified and it was ASC, change to DESC
sort_order_value = 'DESC';
else //if order wasnt selected, default is ASC and if DESC was sent, change to ASC
sort_order_value = 'ASC';
</cfscript>
<cfoutput>
<!--- for debugging --->
isPost: #isPost#<br>
chkbox1Selected: #chkbox1Selected#<br>
chkbox2Selected: #chkbox2Selected#<br>
chkbox3Selected: #chkbox3Selected#<br>
sort_order_value: #sort_order_value#<br>
<cfif structKeyExists(form, 'sort_order')>
form.sort_order: #form.sort_order#<br>
</cfif>
<!--- end of debugging --->


<form action="view_emp_qual.cfm?show=yes" id="Myform" method="post" name="myform">
<!--- brought this here to save the current order value and the sort order being use. Meaning it can be used with other order keys --->
<input type="hidden" name="order_by" id="order_by_id" value="#order_by_value#">
<input type="hidden" name="sort_order" id="sort_order_id" value="#sort_order_value#">
<table id="tab1" align="center">
<tr>
<td>
<input type="checkbox" onclick="return callme();" <cfif chkbox3Selected> checked="checked" </cfif> name="chkbox3" id="chkbox3">
<strong>All Employees</strong>

<input type="checkbox" onclick="return callme1();" <cfif (NOT isPost) OR chkbox1Selected> checked="checked" </cfif> name="chkbox1" id="chkbox1" />
<strong>Agreement Only</strong>

<input type="checkbox" onclick="return callme1();" <cfif (NOT isPost) OR chkbox2Selected> checked="checked" </cfif> name="chkbox2" id="chkbox2"/>
<strong>Active Employees</strong>
</td>
</tr>
<tr>
<td>
<input type="Submit" name="submitnow" value="View Selected" class="button1">
</td>
<td>
<!-- my code here can be optimized. I am only trying to represent the status of the order key. Whether it is being used (and is asc or desc) or it is not being used-->
<cfif order_by_value eq "EMPLID">
<cfif sort_order_value eq "asc"> <!--- comparison is case insenstive --->
<a href="##" style="background-color:##666666;font-weight:bold" onClick="sortBy('EMPLID');"> EMPLID desc<img src="images/desc.jpg"> </a> <!--- bolden order_by if currently used --->
<cfelse>
<a href="##" style="background-color:##000000;font-weight:bold" onClick="sortBy('EMPLID');"> EMPLID asc<img src="images/asc.jpg"> </a>
</cfif>
<cfelse>
<a href="##" style="" onClick="sortBy('EMPLID');"> EMPLID </a> <!--- inherits current sort_order_value when clicked --->
</cfif>
</td>
<td>
<input type="button" name="Back" value="Back to Previous Menu" onclick="javascript:document.location.href('qualyrs_maint.cfm');" class="button1">
</td>
</tr>
</table>
</form>


</cfoutput>
<script language="Javascript">
function sortBy(order) {
foo = document.getElementById("order_by_id");
foo.value = order;
myform.submit();
}
</script>

关于javascript - 以 coldfusion 形式提交时未选中复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17156713/

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