Link to home
Start Free TrialLog in
Avatar of Shrikanaskar
Shrikanaskar

asked on

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>
Avatar of archrajan
archrajan

<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
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shrikanaskar

ASKER

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
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.
oops, but I forgot to give each form a unique name in my example... but you get the idea.  Thanks for the A!  :)