views:

21

answers:

1

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 textbox.value > 0 then raise error.

any ideas?

+1  A: 

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>
Sparafusile
perfect. thanks
oksdd
@oksdd If you like my answer you might consider accepting it as the answer to your question.
Sparafusile