Javascript question on customvalidation

G

gane kol

Hi

I have a set of Yes/No radio buttons with textboxes for each. I need to
write a common customvalidation function that checks, if radiobutton "yes"
is selected, the value in the corresponding textbox should be greater than
0.

For eg:
IsVM Qty: <radX0Yes> YES <radX0No> NO Qty: <txt00>
IsVM1 Qty: <radX1Yes> YES <radX1Yes> NO Qty: <txt11>
IsVM2 Qty: <radX2Yes> YES <radX2Yes> NO Qty: <txt22>
IsVM3 Qty: <radX3Yes> YES <radX3Yes> NO Qty: <txt33>

I created a customvalidator with clientsidevalidation for each set.
<asp:CustomValidator id="cvVM" runat="server" ErrorMessage="Required"
ControlToValidate="txtVMQty"
ClientValidationFunction="ValidateQty('radX0Yes','txt00')"></asp:CustomValid
ator>

function ValidateQty(objRadId,objTxtBoxId){

if (document.getElementById(objRadId).checked){

if (document.getElementById(objTxtBoxId).value <= 0){

arguments.IsValid = false; ??????

}}}

How can i make the arguments.IsValid to false or true based on the
condition?

Thanks
Gane
 
B

Brock Allen

It should be just this: ClientValidationFunction="ValidateQty"

And the signature of the method should take 2 arguments, the first is the
validation tag and the seconds is the args to say if valdation passed or not:

function ValidateQty(sender, args){
if (document.getElementById(sender.controltovalidate).checked){
if (document.getElementById(sender.controltovalidate).value <= 0){

args.IsValid = false;

}}}
 
G

gane kol

i am trying to write a general function.
I need to pass the webcontrol ids as paramater to the function as well.

the code looks like and i have similar codeblocks like below
---------
<asp:radiobutton id="radVMYes" runat="server" CssClass="radbtn" Text="Yes"
GroupName="radVM"></asp:radiobutton>
<asp:radiobutton id="radVMNo" runat="server" CssClass="radbtn" Text="No"
GroupName="radVM" Checked = "true"></asp:radiobutton>
&nbsp;&nbsp;Qty:&nbsp;<asp:textbox id="txtVMQty" runat="server" Columns="2"
cssclass="txtinput" enabled = "false">0</asp:textbox>
<asp:CustomValidator id="cvVMail" runat="server" ErrorMessage="Required"
ControlToValidate="txtVMQty"
ClientValidationFunction="ValidateQty"></asp:CustomValidator>
 
W

William F. Robertson, Jr.

You could place them as an attribute on your validator.

<asp:CustomValidator
id="cvVMail"
runat="server"
ErrorMessage="Required"
ClientValidationFunction="ValidateQty"
cbControl="radVMYes"
txtControl="txtVMQty"
/>

Notice I removed the ControlToValidate property.

Your custom validation will now look something like this.

function ValidateQty( object, args )
{
if ( document.all[object.cbControl].checked == true ) {
if ( document.all[object.txtControl].value == "" )
args.isValid = false;
}

args.isValid = true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top