Radio button validation

D

David

Hi,

I am having a slight problem validating radio buttons using customvalidator.

My buttons generated HTML look like...
<input id="MemberPage_MinorWorks_SpareLoadYesRadioButton" type="radio"
name="MemberPage:MinorWorks:SpareLoadCapacity"
value="SpareLoadYesRadioButton" />

<input id="MemberPage_MinorWorks_SpareLoadNoRadioButton" type="radio"
name="MemberPage:MinorWorks:SpareLoadCapacity"
value="SpareLoadNoRadioButton" />

In my JS, I have...

function CircuitTestedCheck(oSrc, args){
if(document.all['<%=SpareLoadYesRadioButton.ClientID%>'].checked == false
&& document.all['<%=SpareLoadNoRadioButton.ClientID%>'].checked == false){
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

which is referenced by the custom validator.

The ClientID when generated follows the ID not the name of the control, but
I think the JS will require the name, which looks very different.

I was doing exactly this for checkboxes. What should I do for the radio
buttons?

Thanks.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

Of course...

Why didn't I think of that. I will try it.

Thank you.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Teemu Keiski said:
Use document.getElementById instead of document.all


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

David said:
Hi,

I am having a slight problem validating radio buttons using
customvalidator.

My buttons generated HTML look like...
<input id="MemberPage_MinorWorks_SpareLoadYesRadioButton" type="radio"
name="MemberPage:MinorWorks:SpareLoadCapacity"
value="SpareLoadYesRadioButton" />

<input id="MemberPage_MinorWorks_SpareLoadNoRadioButton" type="radio"
name="MemberPage:MinorWorks:SpareLoadCapacity"
value="SpareLoadNoRadioButton" />

In my JS, I have...

function CircuitTestedCheck(oSrc, args){
if(document.all['<%=SpareLoadYesRadioButton.ClientID%>'].checked ==
false && document.all['<%=SpareLoadNoRadioButton.ClientID%>'].checked ==
false){
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

which is referenced by the custom validator.

The ClientID when generated follows the ID not the name of the control,
but I think the JS will require the name, which looks very different.

I was doing exactly this for checkboxes. What should I do for the radio
buttons?

Thanks.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 

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,770
Messages
2,569,586
Members
45,082
Latest member
KetonaraKetoACV

Latest Threads

Top