Solution 1 :

It doesn’t look like you’re passing the click event to myfunction. Try onclick="myfunction(event)".

Problem :

I have a function “myfunction” applied on a submit button. The function shows a dialog box when the page is submitted and asks user if he is sure to submit the page?

The code of HTML button is:

<h:commandButton id="submit" value="Brewery 1" onclick="myfunction()" styleClass="button1">
<f:actionListener binding="#{loginweb.setNewUsernameAndCreateUser('Brewery1')}"/>

**function myfunction(e)**
         if(!confirm('Are you sure to proceed with this role?')) {
        else {
         return false;

But when I press cancel (on appeared dialog box) the page is still submitted. What I am doing wrong? Thanks


Comment posted by epascarello


Comment posted by Onkar

I think you need to apply the function and check