0

i'm working with primefaces commandButton with onclick and action, i want to prevent onclick from execute action method when onclick function return false

CommandButton :

  <p:commandButton value="calc"action="#{bean.actionMethod()}"  oncomplete="DataReturn(xhr, status, args)" onclick="javaScriptOnclickmethod();">
          </p:commandButton>

JavaScript :

function javaScriptOnclickmethod(){

    var code = document.getElementById("form:idS").value;
    if(code.trim() !== '') {
    return true;
    } else {
             return false;

        }
}

what should i do to stop on the onlick function when returning false

Hamza Toussi
  • 108
  • 10
  • You're not returning the result of function call in `onclick`. – BalusC Mar 18 '16 at 15:16
  • @BalusC please what should i do to get this to work ? – Hamza Toussi Mar 18 '16 at 15:17
  • See also http://stackoverflow.com/questions/7814949/javascript-onclick-return-functionality – Kukeltje Mar 18 '16 at 15:24
  • onclick="return javaScriptOnclickmethod();" i did this but when the method return false it reload the whole page, i don't know why !! @BalusC – Hamza Toussi Mar 18 '16 at 15:50
  • Press F12 and check JS console for clues. Big chance it just threw a JS error. – BalusC Mar 18 '16 at 15:55
  • nothing happen on the JS console, it just reload the page when the onclick function return true ! @BalusC – Hamza Toussi Mar 18 '16 at 15:59
  • That's normal behavior. Perhaps you mixed true and false? – BalusC Mar 18 '16 at 16:03
  • function sendAutCptValuesToBean(){ PF('start').show(); var cdRamss = document.getElementById("form1:idrs_input").value; if(cdRamss.trim() !== '') { document.getElementById("form1:cdRmsHD").value = cdRamss; } else { PF('start').hide(); alert("Ramasseur Vide !"); return false; } } and my commandButton is like @BalusC – Hamza Toussi Mar 18 '16 at 16:05

0 Answers0