动态ASP复选框上的复选框验证 [英] Checkbox Validation on Dynamic ASP Checkboxes

查看:93
本文介绍了动态ASP复选框上的复选框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,


我被告知要在Javascript论坛中发布这个我想做的事情

这个客户端就在我的表单获得之前提交。一旦用户点击提交按钮,就需要运行javascript函数并且

验证我的表单上的所有复选框,并确保它们都不是

未选中。我吮吸Javascript,我的问题是2倍。我有以下代码构建复选框


展开 | 选择 | Wrap | 行号

解决方案

cl********@hotmail.com 写道:

我有以下代码构造复选框

展开 | 选择 | Wrap | 行号




Ben Amada写道:

cl ******* *@hotmail.com 写道:

我有以下代码构造复选框

展开 | 选择 | Wrap | 行号

cl********@hotmail.com 写道:

Ben Amada写道:


嗨。这是一个相当不错的方法:

1.使用序号(chk1,chk2
... chk7)为每个复选框分配一个唯一的ID。在ASP代码中,您可以通过创建每次输出复选框控件时递增1的整数变量来执行此操作。

2.将最大的序号存储在隐藏字段中(例如,
7)。

3.在验证例程中,使用for和for。循环 - 从1到7循环 -
检查每个复选框的状态。

Ben



你好,
<我不得不说我不明白。我不想改变结构,因为到目前为止一切正常。
你能否用一些代码澄清你的观点。对不起。




下面的代码是未经测试的,但是应该让你接近你正在寻找的东西

for what你已经有了:


=== ASP代码===


Dim iCheckboxID As Integer

iCheckboxID = 0


虽然不是objRS.EOF


iCheckboxID = iCheckboxID + 1


response.write"< input type ="" checkbox"" ID = QUOT;"" &安培; _

" chk" &安培; iCheckboxID& """名称= QUOT;"问题" &安培; _

objRS(" Question_ID")& """值= QUOT;"" &安培; _

objTxt(" Sub_Text")& """>" &安培; _

objTxt(" Text")& "<峰; br>" &安培; chr(13)


objRS.MoveNext


结束时


response.write" < input type ="" hidden"" " &安培; _

" id ="" CheckboxCount"" " &安培; _

" value =""" &安培; iCheckboxID& """>"


=== JavaScript代码===


函数validateCheckBoxes(){

var bFlag = false;

var iCheckboxCount = document.getElementById(''CheckboxCount'')。value;

for(var i = 1; i < = iCheckboxCount; i ++){

if(document.getElementById(" chk" + i).checked){

bFlag = true;

}

}

if(!bFlag){

alert(你还没有检查过任何东西);

返回false;

} else {

var oForm = document.SurveySubmitted; //更改为真实姓名

oForm.submit();

}

}


Hello Experts,

I have been told to post this in the Javascript forum as I want to do
this client side just before my form gets submitted. Once the user
clicks the submit button a javascript function needs to run and
validate all the checkboxes on my form and make sure none of them are
unchecked. I suck at Javascript and my problem is 2fold. I have the
following code that constructs the checkbox

Expand|Select|Wrap|Line Numbers

解决方案

cl********@hotmail.com wrote:

I have the
following code that constructs the checkbox

Expand|Select|Wrap|Line Numbers



Ben Amada wrote:

cl********@hotmail.com wrote:

I have the
following code that constructs the checkbox

Expand|Select|Wrap|Line Numbers


cl********@hotmail.com wrote:

Ben Amada wrote:


Hi. Here''s a pretty decent approach:

1. Assign each checkbox a unique ID using sequential numbers (chk1, chk2
... chk7). In your ASP code, you can do this by creating an integer
variable you increment by 1 each time you output a checkbox control.

2. Store the largest sequential number in a hidden field (for example,
7).

3. In validation routine, use a "for" loop -- looping from 1 thru 7 --
checking the status of each checkbox.

Ben



Hi Ben,

I''m going to have to say I don''t understand. I do not wish to change
the structure since everything is working fine up until this point.
Could you clarify your point with some code. Sorry.



The code below is untested, but should get you close to what you''re looking
for with few changes to what you''ve already got:

=== ASP code ===

Dim iCheckboxID As Integer
iCheckboxID = 0

While Not objRS.EOF

iCheckboxID = iCheckboxID + 1

response.write "<input type=""checkbox"" id=""" & _
"chk" & iCheckboxID & """ Name=""Question" & _
objRS("Question_ID") & """ Value=""" & _
objTxt("Sub_Text") & """>" & _
objTxt("Text") & "<br>" & chr(13)

objRS.MoveNext

End While

response.write "<input type=""hidden"" " & _
"id=""CheckboxCount"" " & _
"value=""" & iCheckboxID & """>"

=== JavaScript code ===

function validateCheckBoxes(){
var bFlag = false;
var iCheckboxCount = document.getElementById(''CheckboxCount'').value;
for (var i=1; i <= iCheckboxCount; i++) {
if (document.getElementById("chk" + i).checked) {
bFlag = true;
}
}
if (!bFlag) {
alert("you haven''t checked anything");
return false;
} else {
var oForm = document.SurveySubmitted;//change to real name
oForm.submit();
}
}


这篇关于动态ASP复选框上的复选框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆