Solved

Javascript - Auto Submit Form

Posted on 2011-03-16
3
496 Views
Last Modified: 2012-06-27
I have a senario, where my client operates on many platforms, all that require their users to login and in most cases with different credentials for each platform.

I have suggested a master slave relationship, whereby the master site maintains a database that stores all other platform login details.

So upon logging into the master site, the user can easily login to any of the slave sites, without needing to enter additional login details.

The login details for each slave site would be stored in a database record.

However having looked at some of the existing platforms, they all use the "post" methods for the login form, so I was planning on therefor submittin g the form via javascript...

(I've tried the code below, but it doesn't work) Is this because the target (action) is on another domain / server, or is there something wrong with the javascript?

Many thanks

<body onload="submitForm()">
<form method="post" action="http://www.slavedomain.co.uk/index.php" name="myForm" id="myForm">
<input type="hidden" name="username" value="candidate" />
<input type="hidden" name="passwd" value="candidate" />
</form>
<!-- now send the form! -->
<script type='text/javascript'>document.myForm.submit();</script>
</body>

Open in new window

0
Comment
Question by:garethtnash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 35152184
I tried your code and it worked for me.  I changed the action to point to my web site so i could test it.

I tried it on both IE and Firefox.

Cross-domain link is not an issue.

The onload=...  in the body tag is extraneous and may be causing a quiet error.  You are doing the submit using in-line javascript (document.myForm.submit();)  It might be better to do it in the onload anyway:

Try this:

<body onload="document.myForm.submit();">
<form method="post" action="http://www.slavedomain.co.uk/index.php" name="myForm" id="myForm">
<input type="hidden" name="username" value="candidate" />
<input type="hidden" name="passwd" value="candidate" />
</form>
</body>

Open in new window

0
 

Author Comment

by:garethtnash
ID: 35152219
Spot on - thank you, I missed some variables :)
0
 

Author Closing Comment

by:garethtnash
ID: 35152228
Thank you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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