简体   繁体   中英

How to get data from a form and post it into iframe?

So I have a form ...

<fieldset>
<legend>Post a comment:</legend>
<form target="forum" method="post" action="forum.**SomeKindOfExtension**" >
                Name: <br />
        <input type="text" name="fname" /><br />
                Subject:<br />
        <input type="text" name="subject" size="50"/><br />
                Comment:<br />
<textarea name="comment" rows="10" cols="100">Hello,</textarea><br />

<input type="submit" value="Send" />
<input type="reset" value="Reset" />

</fieldset>
</form>

Then I want to take the data (name, subject and comment) and put that into an iframe ...

<iframe name="forum" src="forum.**SomeKindOfExtension**" 
width="900" height="500" ></iframe>

Hopefully you can see my problem, which is what type of file will read the form data and display it in the iframe window ? When I've been looking up answers people seem to be using javascript or php but I can't seem to make any of the code work for me.

So if anyone could help me here that would be much appreciated.

Using a iframe on the same page would make no sense because when you click on the submit button the whole page will be submitted to a different page specified it the action attribute of the form.

Instead you could use a different button (not the submit button) to send data to the iframe or use a parent page and then include your two frames ie the form and the iframe.

Here's the first example

mainpage.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>

          <iframe src="frame.html" width="100%" height="100%" name="someFrame"></iframe>

          <FORM name="form1">
               <INPUT type="button" value="Click Me" 
               onClick="someFrame.document.form1.text1.value='Me!'">
          </FORM>
     </BODY>
</HTML>

frame.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>
          <FORM name="form1">
               <INPUT type="text" name="text1" size="25" value="">
          </FORM>
      </BODY>
</HTML>

Here's the second example

parent.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <FRAMESET cols="80%,20%">
          <FRAME SRC="left.html" name="left_frame">
          <FRAME SRC="right.html" name="right_frame">
     </FRAMESET>
</HTML>

left.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>
          <FORM>
               <INPUT type="button" value="Click ME" 
               onClick="parent.right_frame.document.form1.text1.value='Me!'">
          </FORM>
     </BODY>
</HTML>

right.html

<HTML>
     <HEAD>
          <TITLE>JavaScript Example</TITLE>
     </HEAD>

     <BODY>
          <FORM name="form1">
               <INPUT type="text" name="text1" size="25" value="">
          </FORM>
      </BODY>
</HTML>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM