You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wolfgang Frank <wo...@bms.com> on 2001/11/29 14:00:54 UTC

Problem: JavaScript in StrutsForm

Hello there,

may someone help me please?

I tried to call a javascriptfunction from a Struts-Form. I need
to do this because I want to calculate values in another SELECT
box depending
on the choice of this one ... and because a value changed event
in a form doesn´t cause a submit ... i need this?!

And i can´t get it to work:

<html:form action="assignDocument.do" >
      <table>
        <tr>
          <td>Choose:</td>
          <td>
              <html:select property="typeId" size="1"
onchange='document.forms[0].submit()'>
                  <html:options collection="typeRefCodes"
property="refC" labelProperty="refT"/>
               </html:select>
          </td>
        </tr>

....


</html:form>

I get an javascript error that "submit" is not a function.

Does anybody have an idea. It works fine without the javascript
and everything seems to be configured properly.

Thanks in advance
Wolfgang

------------------------------------
Herr Dipl. Math. Wolfgang Frank
Email: Wolfgang.Frank@bms.com
------------------------------------




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem: JavaScript in StrutsForm

Posted by Wolfgang Frank <wo...@bms.com>.
Hi David and Rob & everybody !

Thanks for your help!

Your ideas were right. The problem is caused by the <html:submit> tag at the end of
the form.
I can still use this strus submit tag, when i give it a different 'propertyname'
than 'submit' - which ist the
default value.

Here ist the code that works:

<html:form action="assignDocument.do" >

    <html:select property="typeId" size="1"  onchange="submitForm()">
         <html:options collection="typeRefCodes" property="refC"
labelProperty="refT"/>
     </html:select>

<html:submit property="new"><bean:message
key="FORM_global.button_new"/></html:submit>

</html:form>

Thanks once again and bye
Wolfgang

 ------------------------------------
> Herr Dipl. Math. Wolfgang Frank
> Email: Wolfgang.Frank@bms.com
------------------------------------

##############################################################################
----------------------------------------------------
Wolfgang

You probably have a <html:submit> tag? Struts generates a button with a
name of 'submit' so JavaScript gets confused. It wasted so much of my time!

You need to give your submit button a different name - can't recall how to
do that right now because I stopped using the submit buttons and used links
instead

Rob Breeds




David Lauta wrote:

> Here is what I have found to work:
> I think there might be a bug though
>
> <script language="javascript">
> function submitForm()
> {
>  document.forms[0].submit();
>  return ( true );
> }
> </script>
>
>   <form:select property="firmId"
>    ondblclick="javascript:submitForm()"
>    onchange="javascript:submitForm()" >
>
>    <BR>
>    <form:options collection="firms" property="value" labelProperty="label" />
>   </form:select>
>
> Populating the options was a little tricky.
>
> The bug comes from the use of:
>   <html:submit>
>    <bean:message key="button.insert"/>
>      </html:submit>
>
> This tag adds a submit object to the document.forms[0]
> this causes (netscape at least)  to report document.forms[0].submit()  no such
> method
> To fix this  use  <input type="submit"> instead of   <html:submit>
> <bean:message key="button.insert"/>     </html:submit>
>
> There might be another way around this problem.
> Has any one else seen this?
>
> -Dave
>
> Wolfgang Frank wrote:
>
> > Hello there,
> >
> > may someone help me please?
> >
> > I tried to call a javascriptfunction from a Struts-Form. I need
> > to do this because I want to calculate values in another SELECT
> > box depending
> > on the choice of this one ... and because a value changed event
> > in a form doesn´t cause a submit ... i need this?!
> >
> > And i can´t get it to work:
> >
> > <html:form action="assignDocument.do" >
> >       <table>
> >         <tr>
> >           <td>Choose:</td>
> >           <td>
> >               <html:select property="typeId" size="1"
> > onchange='document.forms[0].submit()'>
> >                   <html:options collection="typeRefCodes"
> > property="refC" labelProperty="refT"/>
> >                </html:select>
> >           </td>
> >         </tr>
> >
> > ....
> >
> > </html:form>
> >
> > I get an javascript error that "submit" is not a function.
> >
> > Does anybody have an idea. It works fine without the javascript
> > and everything seems to be configured properly.
> >
> > Thanks in advance
> > Wolfgang
> >
> > ------------------------------------
> > Herr Dipl. Math. Wolfgang Frank
> > Email: Wolfgang.Frank@bms.com
> > ------------------------------------
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> Thank you,
> David Lauta
> lautad@gate.net
> (561)272-2698
> (561)289-0502 cell


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problem: JavaScript in StrutsForm

Posted by David Lauta <la...@gate.net>.
Here is what I have found to work:
I think there might be a bug though

<script language="javascript">
function submitForm()
{
 document.forms[0].submit();
 return ( true );
}
</script>


  <form:select property="firmId"
   ondblclick="javascript:submitForm()"
   onchange="javascript:submitForm()" >

   <BR>
   <form:options collection="firms" property="value" labelProperty="label" />
  </form:select>

Populating the options was a little tricky.

The bug comes from the use of:
  <html:submit>
   <bean:message key="button.insert"/>
     </html:submit>

This tag adds a submit object to the document.forms[0]
this causes (netscape at least)  to report document.forms[0].submit()  no such
method
To fix this  use  <input type="submit"> instead of   <html:submit>
<bean:message key="button.insert"/>     </html:submit>

There might be another way around this problem.
Has any one else seen this?

-Dave


Wolfgang Frank wrote:

> Hello there,
>
> may someone help me please?
>
> I tried to call a javascriptfunction from a Struts-Form. I need
> to do this because I want to calculate values in another SELECT
> box depending
> on the choice of this one ... and because a value changed event
> in a form doesn´t cause a submit ... i need this?!
>
> And i can´t get it to work:
>
> <html:form action="assignDocument.do" >
>       <table>
>         <tr>
>           <td>Choose:</td>
>           <td>
>               <html:select property="typeId" size="1"
> onchange='document.forms[0].submit()'>
>                   <html:options collection="typeRefCodes"
> property="refC" labelProperty="refT"/>
>                </html:select>
>           </td>
>         </tr>
>
> ....
>
> </html:form>
>
> I get an javascript error that "submit" is not a function.
>
> Does anybody have an idea. It works fine without the javascript
> and everything seems to be configured properly.
>
> Thanks in advance
> Wolfgang
>
> ------------------------------------
> Herr Dipl. Math. Wolfgang Frank
> Email: Wolfgang.Frank@bms.com
> ------------------------------------
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
Thank you,
David Lauta
lautad@gate.net
(561)272-2698
(561)289-0502 cell