[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2947
  • Last Modified:

How to create a hidden IFrame submit a form

I have a HTML form which will submit to a DLL file originally. Now I need to amend the logic that when the user clicks the submit button at the orginal HTML form, it will submit to one more asp too.

What I can think of to reduce the impact on the logic and screen layout is to

1. create a hidden IFrame
2. create a Form with pre-defined Hidden values
3. when user clicks the submit button, the values are then passed to the form at the IFrame and then submit too

Is it practical? If yes, any sample coding I can reference from?

Thanks!
0
mscprojhk
Asked:
mscprojhk
  • 3
1 Solution
 
ZylochCommented:
That's possible. Though, why create an IFRAME? You can make another form at top or bottom of page with display:none that would take up no space. This is how you can do it.

<form name="form1" action="something.dll" onSubmit="document.form2.submit();">
<!-- or document.all.form2.submit() but try it without the .all first -->
<input type="text">etc.etc.
</form>
<form style="display:none;name="form2">
<input type="hidden">etc.etc.
</form>
0
 
mscprojhkAuthor Commented:
but, i'm afraid that if the second is using a hidden form, when i submit the 2nd form first, it may already redirect the page to the form action asp. then, i can't submit the 1st form then.

that's why i try to use IFrame that even the 2nd form posted firstly, the result will be shown at the hidden IFrame only, and i can still submit 1st form.

am i right?
0
 
ZylochCommented:
Hmm... I see your problem. You can do it by doing this.

<form name="form1" action="something.dll" onSubmit="iframename.form2.submit();">
<!-- or document.all.form2.submit() but try it without the .all first -->
<input type="text" name>etc.etc.
</form>
<iframe src="testing4.html" name="iframename" height=0 width=0></iframe>

Now, in testing4.html, you put:

<form name="form2" action="someaction.asp">
<input type="text" name="">etc.etc.
</form>

This has been tested to work. If you change iframename, make sure to change it in the onSubmit and the IFRAME tag. If you change form2 as the name as the form in testing4.html, make sure the form2 in the onSubmit is changed also. Everything else you should know how to modify.

Hope this helps. Good luck.

--Zyloch [Note: I have noticed many people using the Hope this helps thing too... I might have to think of a better slogan.]
0
 
ZylochCommented:
Second Note: Please ignore the comment in the above HTML code; it wasn't changed.

In case you were wondering how I tested it, I tested it by having an IFRAME as a form. Both forms had actions that were HTML documents. The hidden IFRAME form had an action to an HTML page that held a <BODY onLoad="window.location.href='http://www.google.com;'">. This should still work even if your IFRAME ASP form redirects the page somewhere else.

--------------------------------------------------------------------------------

Of course, the answer can also be 42 (Hitchhiker's Guide to the Galaxy)-Not a real answer.

--Zyloch. [My newest slogan...]
0
 
Michel PlungjanIT ExpertCommented:
Zyloch: http can do one request at a time. So two forms submitted to the same window will interfere...
The iframe solution is better.

Michel
0

Featured Post

Industry Leaders: 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!

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