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

Attempting to submit a form via JavaScript

Hello,

I am attempting to send a form by using the syntax document.getElementById("ID").submit();

Here is my code:

<?php
echo "<form action='../login.php?pass=yes' id='passForm'>
		<input type='hidden' id='usr' value='". $_POST["usr"]. "' />
		<input type='submit' />
	</form>";
?>
<script language="javascript" type="text/javascript">
                document.getElementById("passForm").submit();
</script>

Open in new window


The $_POST["usr"] is from the form that went to this page.  The submit() is only submitting login.php?.  In other words, even the action string is '../login.php?pass=yes, submit is only using '../login.php?.

if I do alert(document.getElementById("passForm").action), the complete string is displayed.

Any help is greatly appreciated.

Have a great day,

Don
0
GEMCC
Asked:
GEMCC
  • 4
  • 3
1 Solution
 
GaryCommented:
Code works fine but pass=yes will not be passed, it will be replaced with any inputs in the form
0
 
GEMCCAuthor Commented:
So how do I get the complete URL to submit?
0
 
GaryCommented:
Change the FORM METHOD to POST

echo "<form action='../login.php?pass=yes' method='POST' id='passForm'>

Then you can get the url params with $_GET and the FORM values with $_POST
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
GEMCCAuthor Commented:
Thanks!  Now it works!  I forgot about method="post"!
0
 
GEMCCAuthor Commented:
I kinda jumped too soon to mark the answer as accepted.  I am now getting to the proper URL, but <input type='hidden' id='usr' value='". $_POST["usr"]. "' /> is not being posted.  In other words, the value does not go to ../login.php?pass=yes.

Now what am I doing wrong/ missing?

Thanks for your help!
0
 
GaryCommented:
Your input needs a name otherwise it won't be POSTed
0
 
GEMCCAuthor Commented:
Again, a brain fart, I was thinking about CSS (id).

Thanks again
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.

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