I have a JSF button which calls a Javascript function when it is pressed, that function is doing some work and at the end it redirects to another page, it looks like this:
<h:commandButton type="submit" value="Submit" id="button1" onclick="myFunction()">
</h:commandButton>
And the function looks like this:
function myFunction() {
// .....
window.location.href = "/page2.faces";
}
The HTML code is generated fine when the page is opened:
<input type="submit" value="Submit" id="form1:button1" name="form1:button1" onclick="myFunction()" />
The function is executed but the redirection does not work, it remains on the same page. Is there a way to redirect from a Javascript function?
-------UPDATE--------
The form
tag is generated as follows:
<form id="form1" name="form1" method="post" action="/myProject/page1.faces" enctype="application/x-www-form-urlencoded" class="form">
The action
is the same as the first page, seems like when I click the button it navigates to the same page because of this.