我有一个涉及两个单选按钮的问题:是和否。如果选择“否”,则没有任何反应。如果选择“是”,则会出现带有两个单选按钮的另一个问题,同时显示“是”或“否”。问题是当选择“否”时,它不会显示其他问题,这会在提交时出现此错误“
元素Mailincare_1未在类型为coldfusion.filter.FormScope的Java对象中定义。
表单代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="clearfix">
<label for="Mailto_1">Mail to address other than mailing address listed above?</label>
<cfoutput><input type="radio" value="Yes" name="Mailto_1" id="Mailto_1" required="yes" /></cfoutput>
<label for="Mailto_1">Yes</label>
<cfoutput><input type="radio" value="No" name="Mailto_1" id="noMailto_1" /></cfoutput>
<label for="noMailto_1">No</label>
<!---Label is here for placement of error message--->
<label for="Mailto_1" class="error" style="display:none;">Please choose one.</label>
</div>
<!---If Yes (mailto) is selected Dropdown information appears (if none clear text from textboxes)--->
<script type="text/javascript">
$(document).on('change', 'input[name=Mailto_1]', function() {
var value = $(this).val();
if (value == "Yes") {
$('#Mailincare').show();
} else {
$('#Mailincare').hide();
$("#Mailincare_1").prop('checked', false);
$("#noMailincare_1").prop('checked', false);
$("#cfirstname_1").val("");
$("#div2 > .clearfix input:text").val("");
$('#div1').hide();
$('#div2').hide();
}
});
</script>
<div id="Mailincare" class="clearfix" style="display:none">
<label for="Mailincare_1">Mail in care of someone else's name?</label>
<cfoutput><input type="radio" value="Yes" name="Mailincare_1" id="Mailincare_1"/></cfoutput>
<label for="Mailincare_1">Yes</label>
<cfoutput><input type="radio" value="No" name="Mailincare_1" id="noMailincare_1" /></cfoutput>
<label for="noMailincare_1">No</label>
<!---Label is here for placement of error message--->
<label for="Mailincare_1" class="error" style="display:none;">Please choose one.</label>
</div>
很抱歉发布了所有这些内容,但我只想说明如何设置会话。
<cfif structKeyExists(form, "submit")>
<cfset errors = []>
<cfif not arrayLen(errors)>
<cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
<cfset session.checkout.info["firstname_#Add#"]=form["firstname_#Add#"]>
...
<cfif Add EQ 1>
<cfset session.checkout.info["Mailto_#Add#"]=form["Mailto_#Add#"]>
<cfset session.checkout.info["Mailincare_#Add#"]=form["Mailincare_#Add#"]>
...
</cfif>
....
</cfloop>
<cflocation url="vehicleInfo.cfm" addToken="false">
</cfif>
</cfif>
答案 0 :(得分:4)
有几种方法可以解决这个问题。没有特别的顺序,这里有三个
<cfparam>
确保字段始终存在