You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Todor Sergueev Petkov <t....@basalmed.uio.no> on 2003/08/06 13:36:31 UTC

[OFF TOPIC] JavaScript + tag question

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I'd write some sort of function and call it from the event.

onchange="submitFromDropdown(this)"

and your function should be something like this:

submitFromDropdown(dropdown)
{
     //'this' == dropdown field object
     var fieldName = dropdown.name;
     var len = dropdown.options.length;
     var item = '';
     for (i = 0; i < len; i++) {
         if (dropdown.options[i].selected)
             item = dropdown.options[i].value;
     }
     var url = "/search.do?action=" + fieldName
         + "&selectedItem=" + item;
     dropdown.form.action = url;
     dropdown.form.submit();
}

I changed the code from my working code - usual disclaimers apply. You 
might need to debug it a little, but that's easy too.

Adam

Todor Sergueev Petkov wrote:
> I am not very profficient in JavaScript so any help would be appreciated
> :
> 
> 	I would like to do the following :
> 		
> 		I have a form with different fields and drop down boxes
> 		When A drop down box is selectd I would like to do a submit that looks
> more or less like this :
> 
> 			submit=/search.do?action=dropdownbox1&selectedItem=item
> 
> 	I would like to do this because I need the action parameter for my
> DispatchAction class and the selectedItem obviously to know what the
> selection is.
> 	Is there a way to perform this inside a struts select tags event useing
> JavaScript....If so can you give me an example ( short code snippet
> maybe ).
> 
> Thanks,
> 	Todor
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


RE: [OFF TOPIC] JavaScript + tag question

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
I believe that document.forms[0].elements[anySelectbox].value will be 
invalid. .value only works on non-select form-elements. AFAIK without 
testing it now.


Mark Galbreath wrote:
> If you read the API you will see that JavaScript functions are built into
> the Struts <html:select> tag:
> 
> http://jakarta.apache.org/struts/userGuide/struts-html.html#select
> 
> so you have several event handlers to use for transferring control.  E.g.,
> <html:select property="myBean"  onClick="myFunction( 'myBean'
> )"/></html:select>
> 
> <script type="text/javascript>
>   function myFunction( docObject ) {
>     var string = "document.forms[ 0 ].elements[ '" + docObject + "'
> ].value";
>     var selected = string;
>     location = "/search.do?action=" + docObject + "&selectedItem=" + string;
>   }
> </script>
> 
> And map an action path for "search.do" in your struts-config.xml file.
> 
> Mark
> 
> -----Original Message-----
> From: t.s.petkov@basalmed.uio.no [mailto:t.s.petkov@basalmed.uio.no] 
> Sent: Wednesday, August 06, 2003 7:37 AM
> 
> I would like to do the following :
> 		
> I have a form with different fields and drop down boxes
> When A drop down box is selectd I would like to do a submit that looks more
> or less like this :
> 
> submit=/search.do?action=dropdownbox1&selectedItem=item
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 


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


RE: [OFF TOPIC] JavaScript +