Hi
How to validate a radio button? I create atwo radio buttons as a single group with different names "radio1" & "radio2". I used "dmf:requiredfieldvalidator" but its not validating. plz help me.
Thanks in advance
If there are Accepted Answers, those will be shown by default. You can switch to 'All Replies' by selecting the tab below.
You can set value=true for any one radio button. So no need to validate. Anyway one radio button will be selected.
Radio button always must have to set the default properties to true just for one button.
Thanks latha, thanks for the information
one more thing, i want to validate the 2 radio buttons using Required fields validator. i created
<dmf:panel name="mypanel">
<dmf:radiobutton name='"radio1" groupname="myradio">
<dmf:radiobutton name='"radio2" groupname="myradio">
</dmf:panel>
<dmf:requiredfieldvalidator controltovalidate="mypanel" errormessage="non selected" name="myquirede"></dmf:requiredfieldvalidator>
<dmf:button name="mybutton" onclick="buttonclick" />
<script>
function buttonclick()
{
// how to validate the form (i am able to validate using html tags,but i am unable do with dmf tags)
}
</script>
Thanks in advance,
Teja
As per my understanding, you want to validate in client side whether any one of the radio button is selected. If my understanding is correct, u can use the following code to validate in client side.
<%@ page contentType="text/html; charset=UTF-8" %><%@ page errorPage="/wdk/errorhandler.jsp" %><%@ taglib uri="/WEB-INF/tlds/dmform_1_0.tld" prefix="dmf" %>
<html><head></head><script>
if(document.getElementById('radio1').checked || document.getElementById('radio2').checked){
//Place ur code here
alert("Valid"); } else {
//Place ur code here alert("Select any one"); }
</script><webform/><body>
<dmf:form>Enter Some Value
<dmf:radio name="radio1" group="myradio" id="radio1"/>
<dmf:radio name="radio2" group="myradio" id="radio2"/>
<dmf:button name="mybutton" label ='Test' onclick="buttonclick" runatclient='true'/>
</dmf:form></body>
</html>
- You can't validate a panel for required field.
Try giving controltovalidate='myradio', which is name of the group.
Thanks,
Sameer