2 つの関数を呼び出したいのですが、最初の関数が true を返す場合は 2 番目の関数に進み、false を返す場合はエラーを表示します。これは、1 つの onclientclick で定義されます。
ボタンをクリックした後に呼び出される関数が 1 つだけの場合、その関数は機能します。
ただし、次のように組み合わせて記述すると、TestCheckBox() と TestCheckBox2() は同じ関数であり、2 つのグリッドビューを検証するために必要なだけです。
<script type="text/javascript">
var TargetBaseControl = null;
window.onload = function () {
try {
//get target base control.
TargetBaseControl =
document.getElementById('<%= this.GridView1.ClientID %>');
}
catch (err) {
TargetBaseControl = null;
}
}
function TestCheckBox() {
if (TargetBaseControl == null) return false;
//get target child control.
var TargetChildControl = "chkRow";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 &&
Inputs[n].checked)
return true;
alert('Select at least one checkbox!');
return false;
}
</script>
問題は、TestCheckBox() が true を返し、TestCheckBox2() が機能しない場合です。この場合、チェックボックスが検証されません。
完全に機能させるにはどうすればよいですか?