0

I have a jsf form which has a command Button and I have some list of items. So i am going to disable the button when user Selected items count is greater than certain limit(assume it as 10) and again it should enable it back if that count is less than 10 .

My code is working till disabling the button but when the count is less than 10 it not able to enable it again .

Pls check my code below and help

<h:commandButton id="addButton"  value="   ADD -- > " action="#{CW.addTraffic}" disabled="false" onclick="return countValidation();"/>

In js , i wrote the logic for comparing the count

I should show 3 counts in my page . one is max count which is 10 and selectedcount which is coming when we select items and Permit count which is ..

permitcount= 10 - selectedcount  (this vaklue will becomes neagtive if we select more than 10)

if(permitcount<0)
  {

 document.getElementById("main:addButton").disabled='true'; // disable the button 

  }
else
  {

     document.getElementById("main:addButton").disabled='false'; // this should enable .

  }

but it not enabling the button back once it is disabled . pls help me

MRT
  • 1
  • 2
  • How is jsf related? Jsf in this regard is nothing more than an html generator and all you use is javascript. Duplicate assigned (a very little searching in stackoverflow shows many related and even duplicate questions with answers) – Kukeltje May 25 '15 at 12:40
  • Unrelated to the question: keep in mind that users can easily circumvent this 'protection' by using a browser developer tool if you do not have a serverside counterpart of this validation. And if you do, why not use ajax (count serverside and update/warn limits are exceeded and have both client and server automatically? – Kukeltje May 25 '15 at 12:44

0 Answers0