View Full Version : Javascript Radio button that Toggles the Validation between to textbox values

12-01-2009, 01:14 AM
I am using ASP validators and I have a contact form. I want to be able to have a phone and email radio button group. The email textbox also has a RegularExpressionValidator

If the phone item is selected then I want the validation to be enabled on the phone text box making it mandatory while the email text box isn't, and if they choose the email as the contact it will be reversed.

I want to be able to do this without having to do a postback.

I already have the logic on the code behind and the enquiry object.

also I am fairly new to javascript so I have been using mostly jQuery as easier to implement

Old Pedant
12-01-2009, 02:54 AM
Well, ASP.NET isn't really set up to do this, but it's easy enough to do in pure JS code as an "add-on" without ASP.NET being aware of it.

But if you have *other* ASP.NET-driven validation taking place, then you have to figure out how to "hook in" this validation.

If you could remove the ASP.NET RegExp validator from the <form> and then bring up the page in your browser and do a VIEW==>>SOURCE to see the HTML ASP.NET is producing and copy that here, then it would be a lot easier to try to help you. Or just show us the site live, if that's easier/possible.