You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shyam A <st...@yahoo.com> on 2003/07/11 20:15:44 UTC

newbie question - setting form parameter in Javascript

Hi,
 
I have an HTML form with Submit and Cancel buttons, and a drop down list, which when clicked submits the form. I use Javascript to submit the form when the dropdown list is clicked.
I have a property called "action" defined in my ActionForm class that identifies the Submit and Cancel buttons in the HTML form. When the drop-down is clicked, I would like to set the value of this "action" property to "Lookup".
 
My Javascript function is given below:
 
################

<SCRIPT language="JavaScript">
function submitForm(form)
{
form.action.value="Lookup";
form.submit();
return true;
}
#################
 
and I invoke this function in my HTML form as shown below:
 
#########################
 <html:select property="crn" onclick="submitForm(this.form)">
       <html:option value="Test" selected>Test</html:option>       
       </html:select> 
###########################
 
But, the value of the property "action" is not set to "Lookup".
 
Any help would be greatly appreciated.
 
Thanks,
Shyam


---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

Re: newbie question - setting form parameter in Javascript

Posted by James Mitchell <jm...@apache.org>.
I think I see where you are going....try setting the form action instead:

<SCRIPT language="JavaScript">
function submitForm(form) {
document.frm.action="lookup.do";   //  <--Change this to not be hard-coded
form.submit();
return true;
}
</SCRIPT>

<form name="frm" action="?" method="GET">
 <input type="hidden" name="action" value="">
 <select name="crn" onclick="submitForm(this.form)">
   <option value="Test" selected>Test</option>       
   <option value="Test2">Test2</option>       
 </select>
<br>
<input type="submit" name="action" value="Submit">

</form>



On Friday 11 July 2003 15:00, Shyam A wrote:
> James,
>
> Thanks for your mail. I guess I need to elaborate a little bit. My HTML
> form can be submitted in 2ways. 1. Clicking the "Submit" button.
> 2. Clicking the drop-down
>
> Clicking the drop-down triggers a different action than clicking the
> "Submit" button. Selecting a value in the drop-down would submit the form
> and populate some of the other fields in the form. This is done before the
> "Submit" button is clicked. So, I need to distinguish the action of
> clicking the drop-down from clicking the "Submit" button and I called it
> "Lookup".
>
> Both actions would be identified with a single property in the ActionForm
> class - action.
>
> eg:
>  <html:submit property="action" value="Submit"/>
>
> I would like to set this "action" property value to "Lookup" on clicking
> the drop-down using Javascript. I guess a hidden field would not serve the
> purpose as I already have "action" property defined for the Submit button.
>
> Look forward to your help/suggestions.
>
> Thanks,
> Shyam
>
> James Mitchell <jm...@apache.org> wrote:
>
> You will need to create a hidden field named "action", with a value of
> "Lookup":
>
>
>
> My question to you is....why "Lookup"? What does that have to do with your
> form?
>
>
> Here's a sample:
>
>
> function submitForm(form) {
>  form.action.value="Lookup";
>  form.submit();
>  return true;
> }
>
>
>
>  [input]
>  Test Test2
>
> On Friday 11 July 2003 14:15, Shyam A wrote:
> > Hi,
> >
> > I have an HTML form with Submit and Cancel buttons, and a drop down list,
> > which when clicked submits the form. I use Javascript to submit the form
> > when the dropdown list is clicked. I have a property called "action"
> > defined in my ActionForm class that identifies the Submit and Cancel
> > buttons in the HTML form. When the drop-down is clicked, I would like to
> > set the value of this "action" property to "Lookup".
> >
> > My Javascript function is given below:
> >
> > ################
> >
> >
> > function submitForm(form)
> > {
> > form.action.value="Lookup";
> > form.submit();
> > return true;
> > }
> > #################
> >
> > and I invoke this function in my HTML form as shown below:
> >
> > #########################
> >
> >        Test
> >
> > ###########################
> >
> > But, the value of the property "action" is not set to "Lookup".
> >
> > Any help would be greatly appreciated.
> >
> > Thanks,
> > Shyam
> >
> >
> > ---------------------------------
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!

-- 
James Mitchell
Software Developer/Struts Evangelist
http://www.struts-atlanta.org
678-910-8017
AIM:jmitchtx



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


Re: newbie question - setting form parameter in Javascript

Posted by Mark Lowe <ma...@talk21.com>.
check out dispatch actions..

you can have multiple execute methods with dispatch action ...

Your Action class extends DispatchAction instead of action (check the 
docs)

public final ActionForward submit(
						ActionMapping mapping,
						ActionForm form,
						HttpServletRequest request,
						HttpServletResponse response)
	
	  throws Exception {
...
}

public final ActionForward lookup(
						ActionMapping mapping,
						ActionForm form,
						HttpServletRequest request,
						HttpServletResponse response)
	
	  throws Exception {
...
}

in struts config the parameter attibute need to know the name of the 
parameter your about to send, the value of which is your execute method 
name..

<action path="/processForm" type="com.sparrow.struts.MyAction" 
scope="request" parameter="action">
...

and then in jsp

<html:link page="/processForm.do?action=lookup">

<html:link page="/processForm.do?action=submit">


HTH Mark


On Friday, July 11, 2003, at 08:00 PM, Shyam A wrote:

> James,
>
> Thanks for your mail. I guess I need to elaborate a little bit. My 
> HTML form can be submitted in 2ways.
> 1. Clicking the "Submit" button.
> 2. Clicking the drop-down
>
> Clicking the drop-down triggers a different action than clicking the 
> "Submit" button.
> Selecting a value in the drop-down would submit the form and populate 
> some of the other fields in the form. This is done before the "Submit" 
> button is clicked. So, I need to distinguish the action of clicking 
> the drop-down from clicking the "Submit" button and I called it 
> "Lookup".
>
> Both actions would be identified with a single property in the 
> ActionForm class - action.
>
> eg:
>  <html:submit property="action" value="Submit"/>
>
> I would like to set this "action" property value to "Lookup" on 
> clicking the drop-down using Javascript. I guess a hidden field would 
> not serve the purpose as I already have "action" property defined for 
> the Submit button.
>
> Look forward to your help/suggestions.
>
> Thanks,
> Shyam
>
> James Mitchell <jm...@apache.org> wrote:
>
> You will need to create a hidden field named "action", with a value of
> "Lookup":
>
>
>
> My question to you is....why "Lookup"? What does that have to do with 
> your
> form?
>
>
> Here's a sample:
>
>
> function submitForm(form) {
>  form.action.value="Lookup";
>  form.submit();
>  return true;
> }
>
>
>
>  [input]
>  Test Test2
>
>
>
> On Friday 11 July 2003 14:15, Shyam A wrote:
>> Hi,
>>
>> I have an HTML form with Submit and Cancel buttons, and a drop down 
>> list,
>> which when clicked submits the form. I use Javascript to submit the 
>> form
>> when the dropdown list is clicked. I have a property called "action"
>> defined in my ActionForm class that identifies the Submit and Cancel
>> buttons in the HTML form. When the drop-down is clicked, I would like 
>> to
>> set the value of this "action" property to "Lookup".
>>
>> My Javascript function is given below:
>>
>> ################
>>
>>
>> function submitForm(form)
>> {
>> form.action.value="Lookup";
>> form.submit();
>> return true;
>> }
>> #################
>>
>> and I invoke this function in my HTML form as shown below:
>>
>> #########################
>>
>>        Test
>>
>> ###########################
>>
>> But, the value of the property "action" is not set to "Lookup".
>>
>> Any help would be greatly appreciated.
>>
>> Thanks,
>> Shyam
>>
>>
>> ---------------------------------
>> Do you Yahoo!?
>> SBC Yahoo! DSL - Now only $29.95 per month!
>
> -- 
> James Mitchell
> Software Developer/Struts Evangelist
> http://www.struts-atlanta.org
> 678-910-8017
> AIM:jmitchtx
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!


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


Re: newbie question - setting form parameter in Javascript

Posted by Shyam A <st...@yahoo.com>.
James,
 
Thanks for your mail. I guess I need to elaborate a little bit. My HTML form can be submitted in 2ways.
1. Clicking the "Submit" button.
2. Clicking the drop-down
 
Clicking the drop-down triggers a different action than clicking the "Submit" button.
Selecting a value in the drop-down would submit the form and populate some of the other fields in the form. This is done before the "Submit" button is clicked. So, I need to distinguish the action of clicking the drop-down from clicking the "Submit" button and I called it "Lookup".
 
Both actions would be identified with a single property in the ActionForm class - action.
 
eg:
 <html:submit property="action" value="Submit"/>     
 
I would like to set this "action" property value to "Lookup" on clicking the drop-down using Javascript. I guess a hidden field would not serve the purpose as I already have "action" property defined for the Submit button.
 
Look forward to your help/suggestions.
 
Thanks,
Shyam

James Mitchell <jm...@apache.org> wrote:

You will need to create a hidden field named "action", with a value of 
"Lookup":



My question to you is....why "Lookup"? What does that have to do with your 
form?


Here's a sample:


function submitForm(form) {
 form.action.value="Lookup";
 form.submit();
 return true;
}



 [input] 
 Test Test2



On Friday 11 July 2003 14:15, Shyam A wrote:
> Hi,
>
> I have an HTML form with Submit and Cancel buttons, and a drop down list,
> which when clicked submits the form. I use Javascript to submit the form
> when the dropdown list is clicked. I have a property called "action"
> defined in my ActionForm class that identifies the Submit and Cancel
> buttons in the HTML form. When the drop-down is clicked, I would like to
> set the value of this "action" property to "Lookup".
>
> My Javascript function is given below:
>
> ################
>
>
> function submitForm(form)
> {
> form.action.value="Lookup";
> form.submit();
> return true;
> }
> #################
>
> and I invoke this function in my HTML form as shown below:
>
> #########################
>  
>        Test
>        
> ###########################
>
> But, the value of the property "action" is not set to "Lookup".
>
> Any help would be greatly appreciated.
>
> Thanks,
> Shyam
>
>
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!

-- 
James Mitchell
Software Developer/Struts Evangelist
http://www.struts-atlanta.org
678-910-8017
AIM:jmitchtx



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

 


---------------------------------
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!

Re: newbie question - setting form parameter in Javascript

Posted by James Mitchell <jm...@apache.org>.
You will need to create a hidden field named "action", with a value of 
"Lookup":

<html:hidden property="action" value="Lookup"/>

My question to you is....why "Lookup"?  What does that have to do with your 
form?


Here's a sample:

<SCRIPT language="JavaScript">
function submitForm(form) {
 form.action.value="Lookup";
 form.submit();
 return true;
}
</SCRIPT>

<form name="frm" action="?" method="GET">
 <input type="hidden" name="action" value="">
 <select name="crn" onclick="submitForm(this.form)">
   <option value="Test" selected>Test</option>       
   <option value="Test2">Test2</option>       
 </select>
</form>


On Friday 11 July 2003 14:15, Shyam A wrote:
> Hi,
>
> I have an HTML form with Submit and Cancel buttons, and a drop down list,
> which when clicked submits the form. I use Javascript to submit the form
> when the dropdown list is clicked. I have a property called "action"
> defined in my ActionForm class that identifies the Submit and Cancel
> buttons in the HTML form. When the drop-down is clicked, I would like to
> set the value of this "action" property to "Lookup".
>
> My Javascript function is given below:
>
> ################
>
> <SCRIPT language="JavaScript">
> function submitForm(form)
> {
> form.action.value="Lookup";
> form.submit();
> return true;
> }
> #################
>
> and I invoke this function in my HTML form as shown below:
>
> #########################
>  <html:select property="crn" onclick="submitForm(this.form)">
>        <html:option value="Test" selected>Test</html:option>
>        </html:select>
> ###########################
>
> But, the value of the property "action" is not set to "Lookup".
>
> Any help would be greatly appreciated.
>
> Thanks,
> Shyam
>
>
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!

-- 
James Mitchell
Software Developer/Struts Evangelist
http://www.struts-atlanta.org
678-910-8017
AIM:jmitchtx



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


Re: Help needed - running Rick Reumann's lesson 1- Urgent!!

Posted by Rick Reumann <r...@reumann.net>.
On Sat, Jul 12,'03 (08:20 AM GMT-0700), Rajat wrote: 

> Hi,
> 
> I am running the lesson 1( turorial by Rick Reumann)
> and am getting the foll. error:
> 
> Error in using tag library
> uri='/WEB-INF/struts-html-el.tld' prefix='html': The
> Tag class
> 'org.apache.strutsel.taglib.html.ELOptionTag' has no
> setter method corresponding to TLD declared attribute
> 'bundle', (JSP 1.1 spec, 5.4.1)
> probably occurred due to an error in /index.jsp line
> 2:
> <%@ taglib uri="/WEB-INF/struts-html-el.tld"
> prefix="html" %> 
> 
> Please help ASAP.. my journey has Halted!!

You could have just e-mailed me at struts@reumann.net and I would have
replied:) (As much as I'd like to, I don't always get a chance to check
all of these struts lists messages).

I think you must have caught this lesson during a brief transition
stage. A while ago I changed how I defined the tags in the jsp
pages. The current lesson reflects those changes. In the web.xml file
I'm declaring the tags as:

<taglib>
    <taglib-uri>struts/html-el</taglib-uri>
    <taglib-location>/WEB-INF/struts-html-el.tld</taglib-location>
</taglib>

and in the JSP you should then refer to the tag URI as:

<%@ taglib uri="struts/html-el" prefix="html" %>

I'm guessing your web.xml has the set up as above but your JSP is
following the old way I was calling the tags. Please let me know at
struts@reumann.net if this is NOT the case because I want to make sure
there are no errors in those labs.

Thanks,

-- 
Rick



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


Re: [OT] Raj, please start a new message vs reply

Posted by James Mitchell <jm...@apache.org>.
On Saturday 12 July 2003 11:46, Rick Reumann wrote:
> On Sat, Jul 12,'03 (08:20 AM GMT-0700), Rajat wrote:
> > Hi,
> >
> > I am running the lesson 1( turorial by Rick Reumann)
> > and am getting the foll. error:
>
> Also, Rajat, please start a new message (vs replying to a thread) if the
> subject has changed. Now this message as well as my previous one and
> yours is stuck in inappropriate thread. Thanks.

I notice that a lot of people do that.  Perhaps they are not used to threading 
since Outlook has no clue what it is.  Outlook is the only email client that 
I have used that doesn't support it.  

<disclaimer>
"Group by Conversation Topic" is NOT the same as threading!!
</disclaimer>


-- 
James Mitchell
Software Developer/Struts Evangelist
http://www.struts-atlanta.org
678-910-8017
AIM:jmitchtx



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


[OT] Raj, please start a new message vs reply

Posted by Rick Reumann <r...@reumann.net>.
On Sat, Jul 12,'03 (08:20 AM GMT-0700), Rajat wrote: 

> Hi,
> 
> I am running the lesson 1( turorial by Rick Reumann)
> and am getting the foll. error:

Also, Rajat, please start a new message (vs replying to a thread) if the
subject has changed. Now this message as well as my previous one and
yours is stuck in inappropriate thread. Thanks.

-- 
Rick



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


Help needed - running Rick Reumann's lesson 1- Urgent!!

Posted by Rajat Nayer <ra...@yahoo.com>.
Hi,

I am running the lesson 1( turorial by Rick Reumann)
and am getting the foll. error:

Error in using tag library
uri='/WEB-INF/struts-html-el.tld' prefix='html': The
Tag class
'org.apache.strutsel.taglib.html.ELOptionTag' has no
setter method corresponding to TLD declared attribute
'bundle', (JSP 1.1 spec, 5.4.1)
probably occurred due to an error in /index.jsp line
2:
<%@ taglib uri="/WEB-INF/struts-html-el.tld"
prefix="html" %> 

Please help ASAP.. my journey has Halted!!

Thnaks and regds
Rajat Nayer




__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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


Re: newbie question - setting form parameter in Javascript

Posted by Rick Reumann <r...@reumann.net>.
  
> > My Javascript function is given below:
> >
> > ################
> >
> > <SCRIPT language="JavaScript">
> > function submitForm(form)
> > {
> > form.action.value="Lookup";
> > form.submit();
> > return true;
> > }
> > #################
> >
> > and I invoke this function in my HTML form as shown below:
> >
> > #########################
> >  <html:select property="crn" onclick="submitForm(this.form)">
> >        <html:option value="Test" selected>Test</html:option>
> >        </html:select>
> > ###########################
> >
> > But, the value of the property "action" is not set to "Lookup".
> >
> > Any help would be greatly appreciated.

probably an obvious question, but are you sure you have a hidden form
field called "action" on this page so that your javascript function can
set it?

-- 
Rick



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


Re: newbie question - setting form parameter in Javascript

Posted by Firat TIRYAKI <fi...@pleksus.com.tr>.
probably you can not see the javascript error, because the form submits in
the function, remove the submit(); in the function and see the error, and
also I recommend you not to use onclick event, try onchange, it's better in
this situation.

F.

----- Original Message -----
From: "Shyam A" <st...@yahoo.com>
To: <st...@jakarta.apache.org>
Sent: Friday, July 11, 2003 9:15 PM
Subject: newbie question - setting form parameter in Javascript


> Hi,
>
> I have an HTML form with Submit and Cancel buttons, and a drop down list,
which when clicked submits the form. I use Javascript to submit the form
when the dropdown list is clicked.
> I have a property called "action" defined in my ActionForm class that
identifies the Submit and Cancel buttons in the HTML form. When the
drop-down is clicked, I would like to set the value of this "action"
property to "Lookup".
>
> My Javascript function is given below:
>
> ################
>
> <SCRIPT language="JavaScript">
> function submitForm(form)
> {
> form.action.value="Lookup";
> form.submit();
> return true;
> }
> #################
>
> and I invoke this function in my HTML form as shown below:
>
> #########################
>  <html:select property="crn" onclick="submitForm(this.form)">
>        <html:option value="Test" selected>Test</html:option>
>        </html:select>
> ###########################
>
> But, the value of the property "action" is not set to "Lookup".
>
> Any help would be greatly appreciated.
>
> Thanks,
> Shyam
>
>
> ---------------------------------
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!



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