我在这里再次发布此问题,因为我需要上一个问题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>
现在我按照自己的需要工作,除了在选中最后两个复选框时加载页面,然后点击排序列图标,然后检查第一个复选框。请告知我的代码出错的地方。感谢
答案 0 :(得分:0)
你的问题/方法非常混乱,我花了很多时间试图了解你在做什么。我注意到了错误,但无法修复你的代码,因为很难读出你所做的一些事情,我已经创建了类似的东西 - 匆匆忙忙。它使用相同的形式进行排序和演示,并允许您使用其他几个“订单”键(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>