开发者

javascript for two checkboxes in aspx

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 -

If textbox.value > 0 then checkbox1 = checked or checkbox2 = checked. If neither checkboxes checked when tex开发者_JAVA技巧tbox.value > 0 then raise error.

any ideas?


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 );
}

and

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜