我正在尝试验证两个字段。一个是开放时间,另一个是关闭时间。我的验证应该检查关闭时间的值是否不是“00”,我的打开时间的值也应该大于“00”。
我的问题是,我做错了什么?我知道我的功能一定有错误。
这是我到目前为止写的验证:
<script type="text/javascript">
function hoursFunction(formObject, formField, fieldValue)
{
var closeHours = document.getElementById('closeHours#CountVar#');
var openHours = document.getElementById('openHours#CountVar#');
if(closeHours != "00" && openHours == "00")
{
sfm_show_error_msg('Enter a valid opening time');
}
}
这是我的表格样本
<form id="hoursForm" action="physician_businessHours.cfm?docID=<cfoutput>#docid#</cfoutput>" method="post" onsubmit="hoursFunction();">
<input type="hidden" name="postitnow" value="yes">
<table border="1">
<tr>
<th>Day</th><th>Open Time</th><th>Close Time</th>
</tr>
<cfloop from="1" to="7" index="CountVar">
<cfset dayFound= 0>
<tr>
<td><cfif CountVar eq 1>Mon<cfelseif CountVar eq 2>Tues<cfelseif CountVar eq 3>Wednes<cfelseif CountVar eq 4>Thurs<cfelseif CountVar eq 5>Fri<cfelseif CountVar eq 6>Satur<cfelseif CountVar eq 7>Sun</cfif>day</td>
<cfoutput>
<td>
<select id="openHours#CountVar#" name="openHours#CountVar#">
<cfloop query="doctorHours">
<cfloop from="00" to="23" index="OpenHours">
<option value="#openHours#"<cfif TimeFormat(doctorHours.openTime,'HH') EQ OpenHours AND CountVar EQ doctorHours.day > selected="selected"</cfif>>#OpenHours#</option>
</cfloop>
</cfloop>
</select>
</td>
<td>
<select id="closeHours#CountVar#" name="closeHours#CountVar#">
<cfloop query="doctorHours">
<cfloop from="00" to="23" index="closeHours">
<option value="#closeHours#"
<cfif TimeFormat(doctorHours.closeTime,'HH') EQ closeHours AND CountVar EQ doctorHours.day > selected="selected"</cfif>>#closeHours#</option>
</cfloop>
</cfloop>
</select>
</td>
</tr>
<input type="hidden" name="Validate" onValidate="hoursFunction" message="You must select an opening hour">
<input type="submit" value="Update" id="Submit">
'