JavaScript的在ASPX两个复选框 [英] javascript for two checkboxes in aspx

查看:100
本文介绍了JavaScript的在ASPX两个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框和两个复选框与一个提交按钮。我想提出一个的CustomValidator其中应拨打下列条件一个JavaScript -

I have one textbox and two checkboxes with a submit button. I want to put a customvalidator which shall call a javascript for the following condition -

如果textbox.value> 0,则checkbox1 =检查或checkbox2 =检查。如果没有复选框选中时textbox.value> 0,则引发错误。

If textbox.value > 0 then checkbox1 = checked or checkbox2 = checked. If neither checkboxes checked when textbox.value > 0 then raise error.

什么想法?

推荐答案

这就是我假设你想要的:

This is what I'm assuming you want:

function validate()
{
  var t = document.getElementByID( "myTextbox" );
  var c1 = document.getElementByID( "myCheckbox1" );
  var c2 = document.getElementByID( "myCheckbox2" );

  if( t.value != "" )
  {
    if( !(c1.checked || c2.checked) )
    {
      alert( "You didn't do what I wanted you to do. Bad user!" );
      return( false );
    }
  }

  return( true );
}

<form method=post action=blah onsubmit="JavaScript: return( validate() );">
  <input type=text id=myTextbox name=blah><br>
  <input type=checkbox id=myCheckBox1 name=blah><br>
  <input type=checkbox id=myCheckBox2 name=blah><br>
  <input type=submit>
</form>

这篇关于JavaScript的在ASPX两个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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