我在Cold Fusion中有一个表单,其中包含一组复选框。我将此表单提交到页面frag5.cfm。 frag5.cfm中只有一行代码。
ViewData.MyOtherVMProperty
此行显示"值为" - 也就是说,没有选中名称为f1的复选框的表单值。
这是获取这些值的错误方法吗?有人能告诉我正确的事吗?原始表格如下:
<cfoutput>values are #form.f1# </cfoutput>
缺血的代码是:
<form name = "fields"
action = "frag5.cfm"
method = "post"
onkeypress = "return event.keyCode != 13;">
<table style = "margin-left:165px" >
<caption style = "padding-top: 20px" >Restrict Report To: </caption>
<tr>
<td>Master Event:</td>
<td><input type = "checkbox"
id = "cb_e"
name = "f1"
value = ""
onclick = ischecked("cb_e","hid_e")
class = "check1">
<label for = "cb_e"> </label>
<input type = "hidden" name = "finsel" id = "hid_e" value = "unchecked">
</td>
<td style = "width: 25px"> </td>
<td>SubEvent:</td>
<td><input type = "checkbox"
id = "cb_s"
value = ""
name = "f1"
onclick = ischecked("cb_s","hid_s")
class = "check1" >
<label for = "cb_s"> </label></td>
<input type = "hidden" name = "finsel" id = "hid_s" value = "unchecked">
</td>
</tr>
</table>
<table style ="margin-left: 175px; margin-top: 20px;" >
<td style = "width: 150px;" id = "chuprep" class = ixes2">
</td>
<td style = "width: 150px;">
<input type = "Submit"
name ="Submitfin1"
class = "submitbut"
value = "Submit" >
</td>
</tr>
</table>
</form>
答案 0 :(得分:5)
如果您要检查未选中复选框的值,我认为它们不会显示在FORM范围内。如果选中复选框,则应显示它们。您可以使用structKeyExists(FORM, 'f1')
检查值是否存在。
答案 1 :(得分:0)
一直要做的就是在属性值周围加上引号。它们不是强制性的,但它们可以避免出现类似这样的问题。
'
周围没有任何引号onclick
(单一或双重),因此JS没有执行。
添加(并且还修改了你的功能以进行确认),我认为现在一切正常。你能试试吗?
function ischecked(id, passid){
var ischeck = document.getElementById(id);
console.log(ischeck.checked);
if (ischeck.checked) {
document.getElementById(passid).value = "checked";
console.log( 'setting value to checked');
} else {
document.getElementById(passid).value = "unchecked";
console.log( 'setting value to unchecked');
}
console.log( document.getElementById(passid).value );
} //end function ischeck
&#13;
<form name="fields" action="frag5.cfm" method="post" onkeypress="return event.keyCode != 13;">
<table style="margin-left:165px">
<caption style="padding-top: 20px">Restrict Report To:</caption>
<tr>
<td>Master Event:</td>
<td>
<input type="checkbox" id="cb_e" name="f1" value="" onclick='ischecked( "cb_e", "hid_e")' class="check1">
<label for="cb_e"> </label>
<input type="hidden" name="finsel" id="hid_e" value="unchecked">
</td>
<td style="width: 25px"> </td>
<td>SubEvent:</td>
<td>
<input type="checkbox" id="cb_s" value="" name="f1" onclick='ischecked( "cb_s", "hid_s")' class="check1">
<label for="cb_s"> </label>
</td>
<input type="hidden" name="finsel" id="hid_s" value="unchecked">
</td>
</tr>
</table>
<table style="margin-left: 175px; margin-top: 20px;">
<td style="width: 150px;" id="chuprep" class=i xes2 ">
</td>
<td style = "width: 150px; ">
<input type = "Submit "
name ="Submitfin1 "
class = "submitbut "
value = "Submit " >
</td>
</tr>
</table>
</form>
&#13;