0
我有一個表單,用戶可以將系統名稱添加到項目中。所有表單域都是必需的。我以爲我可以只是動態添加行的jQuery表單驗證
$("#btnSave").live("click", function() {
var today = new Date();
var submitReady = 0;
if ($(".location").val() == '')
{
alert('The location was not selected for one of the systems.');
var submitReady = 1
return false;
}
但它只捕獲第一個系統名稱上的錯誤。理想情況下,我想通知用戶錯過了哪些系統名稱,但可能會晚一些。我確定我需要使用.each(),但我不確定在何處或如何包含它。
我嘗試了以下代替上面的if語句,但它在頁面加載時產生了錯誤。
if ($(".location").each(function(index){$(this).val() == '')})
{
alert('No location was specified');
return false;
}
也許。每個()是在正確的軌道,但我把它應用到了錯誤的元素?
下面是被環表單字段:
<cfloop query="rsRequestSystems">
<table cellpadding="3" class="tablesorter">
<tr>
<th class="form"><label>System Name</label></th>
<td><input name="systemname" type="text" class="systemname" value="#rsRequestSystems.systemname#" size="50" maxlength="50">
<div class="SystemNameStatus" style="color:##0000FF"></div></td>
<th class="form"><label>Location</label></th>
<td><select class="location" name="location">
<option></option>
<cfloop query="rsLocations">
<option value="#rsLocations.optionValue#" <cfif rsRequestSystems.location eq rsLocations.optionValue>selected</cfif> >#rsLocations.optionDesc#</option>
</cfloop>
</select></td>
<td rowspan="2" align="center">
<button type="button" class="fg-button ui-state-default ui-corner-all remove_SystemName" style="width:70px;">Remove</button>
<button type="button" class="fg-button ui-state-default ui-corner-all check_SystemName" style="width:70px;">Check</button></td>
</tr>
<tr>
<th class="form"><label>Platform/Model</label></th>
<td> <select class="platform" name="platform">
<option ></option>
<cfloop query="rsPlatform">
<option value="#rsPlatform.optionValue#" <cfif rsRequestSystems.platform eq rsPlatform.optionValue>selected</cfif>>#rsPlatform.optionValue# - #rsPlatform.optionDesc#</option>
</cfloop>
</select>
/
<select class="model" name="model">
<option selected></option>
<cfloop query="rsModels">
<option value="#rsModels.optionValue#" <cfif rsRequestSystems.model eq rsModels.optionValue>selected</cfif>>#rsModels.optionDesc#</option>
</cfloop></select></td>
<th class="form" nowrap><label>Estimated Go Live</label></th>
<td><input type="text" name="goLive" class="datepicker goLive" value="#dateformat(rsRequestSystems.golive,'mm/dd/yyyy')#" size="10"></td>
</tr>
</table>
我只是創建一個循環爲每個表單字段我需要檢查?我喜歡加入焦點,感覺很好。 :) – HPWD 2011-03-11 18:01:37
如果你有多個'select',你想用'class ='location''來驗證,這將會起作用。 – 2011-03-11 18:06:31
我把這個標記爲正確的,因爲對於我提供的代碼,你的解決方案效果很好。我正在做一些調整,如果我能夠運行它,我會在這裏發佈這些代碼給其他可能會遇到此問題的人查看。 – HPWD 2011-03-11 21:30:19