Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable buttons based on a condition in jsp?

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 value of a variable. I know how to disable a button using javascript, but to use it along with the condition in jsp is what I'm not able to figure out. Is it at all possible?

like image 906
Kazekage Gaara Avatar asked Jul 09 '11 05:07

Kazekage Gaara


3 Answers

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

like image 111
Eugene Burtsev Avatar answered Oct 24 '22 16:10

Eugene Burtsev


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"' : ''}/>
like image 8
fujy Avatar answered Oct 24 '22 17:10

fujy


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>
like image 2
kukudas Avatar answered Oct 24 '22 18:10

kukudas