I want to write a javascript validation code for validating that one of f:selectItem must be selected but i m unable to access checked property of f:selectItem through java script. Below is my JSF page.
JSF 页: 1
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<f:view>
<body
<h:form styleClass="form" id="form1"">
<h:selectOneRadio id="searchType" value="#{auditTrailDTO.searchType}">
<f:selectItem itemLabel="Male" itemValue="m"/>
<f:selectItem itemLabel="FeMale" itemValue="f"/>
</h:selectOneRadio>
</h:form>
</body>
</f:view>
</html>
<>AuditTrailDTO.java:
class AuditTrailDTO
private string searchType;
public String getSearchType() {
return searchType;
}
public void setSearchType(String searchType) {
this.searchType = searchType;
}
}
www.un.org/Depts/DGACM/index_spanish.htm Edit:-
I have succeeded in accessing f:selectItem by following way.Now when no one is selected it shows alert message as expected.But it shows alert message even when second of the radio button is selected. I m calling below method on form onsubmit attribut.Any idea please?
function validateForm(){
var searchType = document.getElementsByName("form1:searchType");
var a = !(searchType[0].checked);
var b = !(searchType[1].checked);
if(a&&b){
alert( Please select search type );
return false;
}
return true;
}