Redirecting to different jsp page based on clicking a button
Hello,
I have the following form
<form action="addcomment.jsp" method="post">
Project: <select name="combo" size="1">
<%
List<Project> projects = mgr.getProjects();
for(Project project : projects){
%>
<option value="<%= project.getId()%>"><%= project.getName()%></option>
<%
}
%>
</select>
<input type="submit" name="selectproject" value="Add Comment"></input>
<input type="submit" name="selectproject" value="View Comments"></input>
</form>
I can I change action in form based on which button is clicked. How can I capture the event?
Thanks,
[742 byte] By [
firoza] at [2007-11-26 22:18:51]

# 1
you surely can using javascript... just try with the restrcutured code below
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="javascript">
function FormSubmit(txt){
document.ActionForm.action = txt;
document.ActionForm.submit();
}
</script>
</head>
<body>
<form name="ActionForm" method="post">
Project: <select name="combo" size="1">
<%
List<Project> projects = mgr.getProjects();
for(Project project : projects){
%>
<option value="<%= project.getId()%>"><%= project.getName()%></option>
<%
}
%>
</select>
<input type="button" name="selectproject" value="Add Comment" onclick="FormSubmit('addcomment.jsp')" />
<input type="button" name="selectproject" value="View Comments" onclick="FormSubmit('viewcomment.jsp')" />
</form>
</body>
<html>
Hope this might be of some help :)
REGARDS,
RaHuL
# 2
Try this:
function subm(f,a)
{
f.action=a;
f.submit();
}
...
<FORM name="form1" method="post" action="" target="" >
<INPUT type="button" name="Submit" value="Submit" onclick="subm(this.form,'<?php $_server['php_self'];?>')">
<input type="button" value="Print Envelope" onclick="subm(this.form,'envelope.php')" >
<input type="button" value="Page Two" onclick="sub(this.form,'page2.php')">
mors1a at 2007-7-10 11:14:01 >
