我的剧本
function fnsort(firstname)
{
alert("hi")
alert( $('#hidetxt').val().length);
if($('#hidetxt').val().length ==0 )
{
$("#hidetxt").val("firstname Asc");
// alert( $('#hidetxt').val());
loadval();
alert("asc function")
}
else
{
var str="firstname Asc";
var n=str.split(" ");
if(n[0] == "firstname")
{
$("#hidetxt").val("firstname Desc");
alert("desc function")
$('#hidetxt').val("")
}
else
{
alert("Control is wrong")
}
}
/*document.getElementById('form2').action="display_report.cfm";
document.getElementById('form2').submit(); */
}
function loadval()
{
<cfoutput>
<cfquery name="result" datasource="Training">
select TE.firstname,TE.lastname,TD.deparmentname,TE.salary,TE.DateOfBirth
from TEmployee as TE
inner join Tdepartment as TD
on TE.departmentID=TD.departmentID
where 1 = 1
<cfif len(form.fname) gt 0 >
AND TE.FirstName Like '#Form.fname#%'
</cfif>
<cfif len(form.lname) gt 0>
and TE.LastName Like '#Form.lname#%'
</cfif>
<cfif form.dept neq 0>
and TD.DeparmentName='#form.dept#'
order by "#form.hidetxt#"
</cfif>
<cfif ListLen(Form.salary,'-') EQ 2>
AND TE.salary between #ListGetAt(Form.salary,1,'-')# AND #ListGetAt(Form.salary,2,'-')#
order by "#form.hidetxt#"
</cfif>
</cfquery>
<!--- <cfquery name="result" datasource="Training">
select TE.firstname,TE.lastname,TD.deparmentname,TE.salary,TE.DateOfBirth
from TEmployee as TE,Tdepartment as TD
where TE.departmentID=TD.departmentID
<cfif #len(form.fname)# gt 0 and #len(form.lname)# gt 0>
and TE.firstname=<cfqueryparam value="#Form.fname#" CFSQLType="CF_SQL_VARCHAR"> and TE.lastname=<cfqueryparam value="#Form.lname#" CFSQLType="CF_SQL_VARCHAR">
</cfif>
</cfquery> --->
</cfoutput>
}
</script>
我的HTML
<body onload="loadval()" >
<form method="post" id="form2">
<input type="hidden" name="hidetxt" value="" id="hidetxt">
<table border="1">
<tr>
<td onclick="fnsort('firstname')">
<b>Firstname</b>
</td>
<td>
<b>Lastname</b>
</td>
<td>
<b> Departname</b>
</td>
<td>
<b> Salary</b>
</td>
<td>
<b> Dob</b>
</td>
</tr>
<cfoutput query="result">
<tr>
<td>
<b>#result.firstname# </b>
</td>
<td>
<b>#result.lastname#</b>
</td>
<td>
<b>#result.deparmentname# </b>
</td>
<td>
<b>#result.salary# </b>
</td>
<td>
<b>#result.DateOfBirth#</b>
</td>
</tr>
</cfoutput>
</table>
<!--- <input type="text" name="txtfname" id="txtfname"> --->
</form>
</body>
错误:FORM中未定义元素HIDETXT。请告诉我如何纠正这个
当我单击第一个名称的单元格时,我需要对名字进行排序。我得到这个错误如何获取“form.hidetxt”值。此页面名称为“display_report.cfm”
答案 0 :(得分:0)
#HIDETXT的值为空,因为
<input type="hidden" name="hidetxt" *value=""* id="hidetxt">
默认为空且
loadval()
不会设置此值..此外
function fnsort(firstname)
{
alert("hi")
alert( $('#hidetxt').val().length); // #hidetxt is nul
if($('#hidetxt').val().length ==0 )
{
$("#hidetxt").val("firstname Asc"); // here #hidetxt have to be "firstname Asc"
// alert( $('#hidetxt').val());
loadval();
alert("asc function")
}
else
{
var str="firstname Asc";
var n=str.split(" ");
if(n[0] == "firstname")
{
$("#hidetxt").val("firstname Desc"); // here #hidetxt has to be "firstname Desc"
alert("desc function") // fix ;
$('#hidetxt').val("") // fix ; and #hidetxt will be ""
}
else
{
alert("Control is wrong")
}
}
/*document.getElementById('form2').action="display_report.cfm";
document.getElementById('form2').submit(); */
}
我认为你必须
console.log($('#hidetxt')
测试是否找到该元素..
之后尝试通过运行方法来使用值来启动它..