SuperMoonster
Programmer
Hello everyone, I have a form with 2 html:submit buttons. I want to change the action of the form dynamically: if I click button 1, it call action 1. If I click button 2, it calls action 2. I tried using javascript, but didn't work.I did the following:
as you see, I have a javascript and I'm trying to call it at the onclick event on the button. Isn't working. Does anyone know why?
Does anyone have a better idea? Maybe there's a struts-way to do it...
Sorry if I keep asking a lot of stupid questions. I'll try to make it the last one.
Thanks very much
Code:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@taglib uri="[URL unfurl="true"]http://java.sun.com/jsp/jstl/core"[/URL] prefix="c"%>
<%@ page import="auge.conexao.ColecaoService" %>
<%@ page import="java.util.*" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html:html locale="true">
<head>
<title>Coleção</title>
<html:base/>
</head>
<body bgcolor="white">
<script language="JavaScript">
function go(param) {
if (param == 1) {
document.forms[0].action.value = "/UpdateColecao.do";
}
else {
document.forms[0].action.value = "/DelColecao.do";
}
document.forms[0].submit();
}
</script>
<span style="font-family:Sans-serif;">
<table width="100%" align="center">
<tr><td> Coleção </td></tr>
<tr bgcolor="#000000"> <td></td></tr>
</table>
<br><br><br><br>
<html:errors/>
<br>
<html:form action="/DelColecao.do" method="post" focus="colecao">
<table border="0" align="center">
<tr><td width="50%"> Coleção </td><td width="50%"><html:text property="colecao" value="${requestScope.col.colecao}" readonly="true"/></td></tr>
<tr><td width="50%"> Descricão </td><td width="50%"><html:text property="descricao" value="${requestScope.col.descricao}"/></td></tr>
<tr>
<td width="50%" align="center">
<html:button property="Gravar" value="Gravar" onclick="javascript:go(1)"/>
</td>
<td width="50%" align="center">
<html:button property="Excluir" value="Excluir" onclick="javascript:go(2)"/>
</td>
</tr>
</table><br/>
</html:form>
</span>
</html:html>
as you see, I have a javascript and I'm trying to call it at the onclick event on the button. Isn't working. Does anyone know why?
Does anyone have a better idea? Maybe there's a struts-way to do it...
Sorry if I keep asking a lot of stupid questions. I'll try to make it the last one.
Thanks very much