Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    posting parent and iframe from parent

    Hello all,
    I have a page which has a form and also one iframe in the same. there is a button on the parent form.
    when the button is clicked, i am submitting the iframe and parent both. forms are getting submitted. but when i do print_r for iframe values, it is blank

    below is the code

    Parent page:
    Code:
    <?
    print "<pre>";
    print_r($_POST);
    print "</pre>";
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function validate(){
    	document.getElementById('mainform').submit();
    	window.frames['iframe1'].document.forms[0].submit(); 
    }
    //-->
    </SCRIPT>
     <BODY>
      <FORM METHOD=POST ACTION="" name='mainform' id='mainform'>
    	<TABLE>
    	<TR>
    		<TD>Name</TD>
    		<TD><INPUT TYPE="text" NAME="Name_VC"></TD>
    	</TR>
    	<TR>
    		<TD>Address</TD>
    		<TD><INPUT TYPE="text" NAME="Address_VC"></TD>
    	</TR>
    	<TR>
    		<TD colspan=2><INPUT TYPE="button" name="proceed" value="Save"  onClick="validate();"></TD>
    
    	</TR>
    	</TABLE>
      </FORM>
      <iframe src="test1.php" id='iframe1'></iframe>
     </BODY>
    </HTML>
    iframe page : test1.php
    Code:
    <?
    print "<pre>";
    print_r($POST);
    print "</pre>";
    ?>
    <form name='mainform2' id='mainform2' method='post' action=''>
    Roll number : <INPUT TYPE="text" NAME="Rollnum" value=''>
    Age: <INPUT TYPE="text" NAME="Age_IN" value=''>
     </form>
    Please tell me what is my mistake or how can i achieve values of all 4 fields
    Million thanks

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Try submitting the iframe before dismissing its parent:
    Code:
    <script type='text/javascript'>
    
    function validate()
    {
     window.frames['iframe1'].document.forms[0].submit(); 
     document.getElementById('mainform').submit();
    }
    
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •