• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8750
  • Last Modified:

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

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
Shrikanaskar
Asked:
Shrikanaskar
  • 3
1 Solution
 
archrajanCommented:
<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
 
knightEknightCommented:
another way:

<body onload="document.forms[0].submit();">
0
 
ShrikanaskarAuthor Commented:
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
 
knightEknightCommented:
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
 
knightEknightCommented:
oops, but I forgot to give each form a unique name in my example... but you get the idea.  Thanks for the A!  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now