[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I load (onload) form in struts without selecting submit(struts, javascript)

Posted on 2005-04-06
5
Medium Priority
?
8,623 Views
Last Modified: 2008-01-09
I am using struts.
I would like to run the form "action" as soon as load the form(without selecting submit button)
I have achieved this in other application (no struts) by running java script
<BODY onload="javascript:submitform('myform')">
Appreciate your help.
Please note that submit button is not mandatory, I can remove it.
Thanks
Shri



My JSP:---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<HEAD width="300" height="400">
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" %>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>index.jsp</TITLE>
</HEAD>

<BODY>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@include file="jspf/CatalogHome.jspf"%>
<P><html:errors />
</P>

<html:form action="/login">
  some code to display
</html:form>
<html:submit>
 <bean:message key="button.login"/>
</html:submit>
</BODY>

</html:html>
0
Comment
Question by:Shrikanaskar
  • 3
5 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 13715998
<script>
document.formname.submit();
</script>
where formname is the name of ur form and please put these script tags just above ur closing </body> tag
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 400 total points
ID: 13716726
another way:

<body onload="document.forms[0].submit();">
0
 

Author Comment

by:Shrikanaskar
ID: 13724956
I am using Websphere development studio.
Initially this did not work. I have to restart the Websphere development studio.
It works.
Could you explain what is form[0] ?
What is the logic behind increse this number ? form[1],form[2]....

Thanks
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 13726129
your document has some number of forms that are referenced as an array.  For example, the following three forms can be references as documents.forms[0], document.forms[1], and document.forms[2] respectively:

<BODY>

<FORM name="myForm1">
  <INPUT type="submit" />
</FORM>

<FORM name="myForm1">
  <INPUT type="submit" />
</FORM>

<FORM name="myForm1">
  <INPUT type="submit" />
</FORM>

</BODY>


However, if you give each form a name as above (which is my preference) then you can do as archrajan suggested and reference them by name, e.g. document.myForm1, document.myForm2, and document.myForm3.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 13726138
oops, but I forgot to give each form a unique name in my example... but you get the idea.  Thanks for the A!  :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question