Solved

Attempting to submit a form via JavaScript

Posted on 2014-03-21
7
501 Views
Last Modified: 2014-03-21
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
Comment
Question by:GEMCC
[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
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39946680
Code works fine but pass=yes will not be passed, it will be replaced with any inputs in the form
0
 

Author Comment

by:GEMCC
ID: 39946717
So how do I get the complete URL to submit?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39946720
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Closing Comment

by:GEMCC
ID: 39946726
Thanks!  Now it works!  I forgot about method="post"!
0
 

Author Comment

by:GEMCC
ID: 39946739
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
 
LVL 58

Expert Comment

by:Gary
ID: 39946746
Your input needs a name otherwise it won't be POSTed
0
 

Author Comment

by:GEMCC
ID: 39946749
Again, a brain fart, I was thinking about CSS (id).

Thanks again
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

739 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