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
It doesn't look like you're passing the click event to myfunction
. Try onclick="myfunction(event)"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.