You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Close <ac...@gmail.com> on 2004/07/27 19:06:44 UTC

Using to submit a form...

Hi all,

i have an intermediary page that has two links and two hidden fields
on it.  when i click on a link i would like to be able to submit my
form (hidden fields) to the appropriate page.  i've tried using the
links with forward and with action but they don't appear to 'submit'
the form.  they just take me to the next page.  so i've added onclick
attributes and reassign the action to the form and submit the form,
but now i'm getting errors that i suspect are javascript.  using a
regular submit button submits the form correctly, but isn't an option
in this case.
is there any other way to get around this issue?  or a  better way to
submit a form using a link tag?

here is my form:

<html:form action="/addItemsByProdNbr.do method="post">
  <html:hidden name="shoppingListForm" property="selectedShoppingList" />
  <html:hidden name="shoppingListForm" property="selectedShoppingListGroup" />
  <!--html:submit /-->  <!-- this works if i add a prodType attribute
to the action above... -->
    <table width="601" align="center" cellpadding="10">
      <TR>
        <TD align="center">
          <html:link forward="addMemberByProdNbr"
onclick="sl_addMemberProdNbrs(this.form);" >
            <Strong>Internal Product Number</Strong>
          </html:link>
        </TD>
      </TR>
      <TR>
        <TD align="center">
          <html:link forward="addNonMemberByProdNbr"
onclick="sl_addNonMemberProdNbrs(this.form);" >
            <Strong>NON Internal Product Number</Strong>
          </html:link>						
        </TD>
      </TR>
  </TABLE>
</html:form>
...

the javascript functions are extremely simple and work elsewhere:

function sl_addMemberProdNbrs(frm) {
  frm.action += "?prodType=Member";
  frm.submit();
  return;
}

function sl_addNonMemberProdNbrs(frm) {
  frm.action += "?prodType=NonMember";
  frm.submit();
  return;
}

and my action mapping:

<action path="/addItemsByProdNbr"
parameter="prodType"
type="com.usfood.usfdc.domain.sl.controllers.SLAddAction" 
name="shoppingListForm" >
<forward name="success" path="/jsp/SList/SLAddItemsByProdNbr.jsp" />
<forward name="failure" path="/jsp/SList/SLError.jsp" />
</action>
		
any suggestions would be greatly appreciated.
thanks
andy

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Using to submit a form...

Posted by Andrew Close <ac...@gmail.com>.
Wendy,

Thanks for the reply.  your solution is working for me.  i guess
hidden fields work out better than attempting to use the parameters in
the actionmapping.

thanks again.
andy

On Tue, 27 Jul 2004 10:18:24 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> From: "Andrew Close" <ac...@gmail.com>
> > function sl_addMemberProdNbrs(frm) {
> >   frm.action += "?prodType=Member";
> >   frm.submit();
> >   return;
> > }
> 
> Instead of messing with the action of the form, actually add the attribute
> to the form.  You might need prodType to be an existing, hidden form
> element, then just set it.  My onClick functions look like this:
> function sortByCostCenter() {
>    document.forms[0].mode.value="sortByCC";
>    document.forms[0].target="_self";
>  document.forms[0].submit();
> }
> 
> The 'mode' is a hidden form element, so mode.value is what you set in order
> for it to be sent to the server.
> 
> I'm no JavaScript expert, but it works...
> 
> --
> Wendy
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Using to submit a form...

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Andrew Close" <ac...@gmail.com>
> function sl_addMemberProdNbrs(frm) {
>   frm.action += "?prodType=Member";
>   frm.submit();
>   return;
> }

Instead of messing with the action of the form, actually add the attribute
to the form.  You might need prodType to be an existing, hidden form
element, then just set it.  My onClick functions look like this:
function sortByCostCenter() {
   document.forms[0].mode.value="sortByCC";
   document.forms[0].target="_self";
 document.forms[0].submit();
}

The 'mode' is a hidden form element, so mode.value is what you set in order
for it to be sent to the server.

I'm no JavaScript expert, but it works...

-- 
Wendy


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org