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')}"/>
</h:commandButton>

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

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

Comments

Comment posted by epascarello

onclick=”myfunction(event)”

Comment posted by Onkar

I think you need to apply the function and check

By