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>
精彩评论