Wednesday, March 28, 2012

Validate multiple text boxes together...

Hopefully I can explain this clearly...

I have a form which accepts inputs. I have 10 fields, a few do individual validation (check for date value, etc.)

Specifically, there are 3 fields (textbox1, textbox2, textbox3) and I want to validate that the user either:
- Enter values for all 3 fields, or
- Leave all three blank.

How can I do that?? I've looked into the current .NET validation and I can't figure out how to do it.

Thanks.

You can use javascript..


jodybannon:

Hopefully I can explain this clearly...

I have a form which accepts inputs. I have 10 fields, a few do individual validation (check for date value, etc.)

Specifically, there are 3 fields (textbox1, textbox2, textbox3) and I want to validate that the user either:
- Enter values for all 3 fields, or
- Leave all three blank.

How can I do that?? I've looked into the current .NET validation and I can't figure out how to do it.

Thanks.

You can either use a validation Summary or a Javascript.

Suppose you have a form

<form onSubmit="return Validate">textbox code...goes here..</form>

Now

<script type="text/javascript">

function Validate()

{

//get textboxes

textbox1=document.getElementById(<%=textbox.clientId%>) and so on..

if (textbox1=="")||(textbox2=="")||(textbox3=="")

{

return false;

}

else

return true;

}

</script>

No comments:

Post a Comment