how can I disable a button by checking a condition in my jsp? If true,then the button is enabled,if false,then the button is disabled. The condition would be checking the va
Or simply you could do it using el
directly like this:
<input type="button" ${ condition ? 'disabled="disabled"' : ''}/>
As an example:
<input type="button" ${ someVariable eq 5 ? 'disabled="disabled"' : ''}/>
Try using JSTL construction like this:
<input type="button" <c:if test="${variable == false}"><c:out value="disabled='disabled'"/></c:if>">
For more examples see http://www.ibm.com/developerworks/java/library/j-jstl0211/index.html
My approach would be something like this:
<c:choose>
<c:when test="${condition == true}">
<input type="button" disabled="disabled"/>
</c:when>
<c:otherwise>
<input type="button" />
</c:otherwise>
</c:choose>
If you use Spring's form tag library, you could also write:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form>
...
<form:button type="button" disabled="${condition}">Name of button</form:button>
</form:form>