Currently, I am working on developing multiple JSP pages and I encountered a requirement where I needed to add a function to a button within an already existing form. The challenge was that the form's submit button was configured to navigate to another JSP view as part of the MVC pattern using Slim3 framework on Google AppEngine. I needed to add another button next to the submit button to navigate to a different JSP view. To solve this, I added a new button with the type "button" to the existing form, created a .js file to write JavaScript code for the alternative navigation functionality, and included the .js file in the JSP view. However, despite my efforts, the solution didn't work as expected. Here's the relevant code:
The JSP page containing the form:
...
<body>
<%@ include file="script.js" %>
<%@ include file="../header.jsp" %>
<%@ include file="sidebar.jsp" %>
<div id="content">
<div id="main">
<p>Hello main admin testimonials edit Index !!!</p>
<h2><b>Modifica Testimonial</b></h2>
<form action="update" method="post">
<h3>Nome: </h3>
<textarea name="name">${f:h(testimonial.name)}</textarea><br />
<h3>Cognome: </h3>
<textarea name="surname">${f:h(testimonial.surname)}</textarea><br />
<h3>Dettagli: </h3>
<textarea name="details">${f:h(testimonial.details)}</textarea><br />
<h3>Progetto:</h3>
<select name="projectKey" selected="${f:h(testimonial.projectRef.key)}">
<c:forEach items="${projectsList}" var="project">
<option value="${f:h(project.key)}">${f:h(project.name)}</option>
</c:forEach>
</select>
<br />
<input type="submit" value="Aggiorna"/>
<input type="button" value="Elimina" onclick="deleteFunction()"/>
<input type="hidden" ${f:hidden("key")}/>
</form>
</div>
</div>
</body>
</html>
script.js:
<script type="text/javascript">
function deleteFunction()
{
if (confirm('Ask navigation confirm'))
{
window.navigate("bla bla new view url");
}
else
{
return;
}
}
</script>
EDIT: I have updated the function name to match the actual implementation from my original code.