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

Auto Submit form on page load - Java Script

How do I get the javascript to auto submit a button without the user pressing the button.
I supplied code of what I'm doing. WHat happens is it errors out at the feeds.submit. JScript runtime error: Object doesn't support this property or method. Any suggestions??

<%@Page Language="VB" AutoEventWireup="false" codefile="default.aspx.vb" inherits="default" %>
<html>
<head>
<title></title>
<script type="text/javascript">
  function submitform()
 {
  feeds.submit();
 }
</script>

<body>
<form name = "feeds" action="page.aspx" method="post" >
  <input type="hidden" name="username" value ="user" />
  <input type="hidden" name="password" value ="pass" />
  <input type="hidden" name="submit" value ="login" />
</form>
<script>
  window.onload = submitform;
</script>
</body>
</html>

Open in new window

0
jeffreyjseaman
Asked:
jeffreyjseaman
  • 6
  • 6
  • 4
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try this:

<%@Page Language="VB" AutoEventWireup="false" codefile="default.aspx.vb" inherits="default" %>
<html>
<head>
<title></title>
<script type="text/javascript">
  function submitform()
 {
  document.feeds.submit();
 }
</script>

<body>
<form name = "feeds" action="page.aspx" method="post" >
  <input type="hidden" name="username" value ="user" />
  <input type="hidden" name="password" value ="pass" />
  <input type="hidden" name="submit" value ="login" />
</form>
<script>
  window.onload = submitform();
</script>
</body>
</html>
0
 
leakim971PluritechnicianCommented:
Put this in head section :
<script language="javascript" type="text/javascript">
window.onload = function() { document.forms[0].submit(); }
</script>

Open in new window

0
 
jeffreyjseamanAuthor Commented:
I tried both of them and the answer was that "Object doesn't support this property or method" I even made it just a simple HTML file and the same result.

When I type document.feeds.submit  ( Feeds doesn't populate as an object available in .Net)

@Leakim971: Same thing object doesn't exist.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
just noticed you dont have a closing </head> tag, try adding that and see if it works.
0
 
leakim971PluritechnicianCommented:
Please provide a link to your page
0
 
jeffreyjseamanAuthor Commented:
I did the </head> and that didn't work. The page is locally on my laptop. I don't have it externally at this time.

0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try this:

<%@Page Language="VB" AutoEventWireup="false" codefile="default.aspx.vb" inherits="default" %>
<html>
<head>
<title></title>
<script type="text/javascript">
  function submitform()
 {
   var frm = document.getElementById('frmFeeds');
  frm.submit();
 }
</script>

<body>
<form name="feeds" id="frmFeeds" action="page.aspx" method="post" >
  <input type="hidden" name="username" value ="user" />
  <input type="hidden" name="password" value ="pass" />
  <input type="hidden" name="submit" value ="login" />
</form>
<script>
  window.onload = submitform();
</script>
</body>
</html>

if this doesnt work, the error may not be on that line, although everything looks ok to me
0
 
jeffreyjseamanAuthor Commented:
@The Big Daddy, it didn't work. Here is a screen shot. Thanks
forms.jpg
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
just a shot in the dark, but remove the spaces on this line:

<form name = "feeds"
0
 
leakim971PluritechnicianCommented:
You've a field with the name 'submit' : change its name to something else
0
 
leakim971PluritechnicianCommented:
Never use 'submit' as name
0
 
jeffreyjseamanAuthor Commented:
@The Big Daddy, did that and didn't help.

@Leakim971, I took the submit out and gave it a different name. It tried to contact the page but said Not Implemented when it executed the window.onload = submitform(); the page then failed.

Thanks
0
 
leakim971PluritechnicianCommented:
Yes there's no action attribute so you'Re looping over and over the samedi page.
0
 
jeffreyjseamanAuthor Commented:
@The Big Daddy and @Leakim971, It is working now. But the only thing is that I receive the message box Implemented. If I click continue it logs me into the other page.

How can I auto select continue instead of manually needing to select it? Here is the screen shot below? Thanks guys
Implemented.jpg
0
 
leakim971PluritechnicianCommented:
change method to GET
0
 
jeffreyjseamanAuthor Commented:
not what i needed.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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