通过POST </div>在单个页面中将值从一个<div>传递到另一个<div>

时间:2013-05-25 03:35:21

标签: php javascript html post

我动态加载了一个页面。在该页面中,我有两个div具有所需的值,或者数据显示在一个diviframe中,并且使用POST将值传递给另一个应该反映在另一个div中的文件或者iframe结果。

请帮我解决这个问题.... 谢谢。

以下是我的示例代码

main.html中

<html>
<head>
</head>
<body>
<div id="leftbar" style="background-color:#eeeeee;width:400px;height:1000px;float:left;position:absolute;">
<iframe src="form1.html" width="1050px" height="1500px" seamless></iframe>
</div>
<div  id="container" style="background-color:#FFD700;height:1000px;width:990px;float:right;">
<iframe src="process.php" name="content" width="1050px" height="1500px" seamless></iframe>
</div>
</body>
</html>

form1.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Hello!</title>
</head>

<body>

 <form name="myform" action="process.php" method="POST"  >
    <input type="hidden" name="check_submit" value="1" />

    Choose the colors:       <br>
      <input type="checkbox" name="Colors[]" value="green" checked="checked" onclick="document.forms.myform.submit();"/> Green<br>
      <input type="checkbox" name="Colors[]" value="yellow" onclick="document.forms.myform.submit();" /> Yellow             <br>
      <input type="checkbox" name="Colors[]" value="red" onclick="document.forms.myform.submit();"/> Red                    <br>
      <input type="checkbox" name="Colors[]" value="gray" onclick="document.forms.myform.submit();" /> Gray                 <br>
    <br /><br />


  </form>


</body>

</html>

process.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Hello!</title>
</head>
<body>
<?php
    if (array_key_exists('check_submit', $_POST)) {
        if (isset($_POST['Colors']) ) {
            $_POST['Colors'] = implode(', ', $_POST['Colors']);
        }
        echo "Colors you chose: {$_POST['Colors']}";
    }
?>

</body>

</html>

1 个答案:

答案 0 :(得分:0)

将您的main.html更改为main.php,而使用表单名称而不是process.php,只需使用main.php

<html >
    <head>
    </head>
    <body>
        <div id="leftbar" style="background-color:#eeeeee;width:400px;height:1000px;float:left;position:absolute;">
            <iframe src="form1.html" width="1050px" height="1500px" seamless></iframe>
        </div>

        <?php
        if (isset($_POST['Colors'])) {
            if (array_key_exists('check_submit', $_POST)) {
                $_POST['Colors'] = implode(', ', $_POST['Colors']);
            }
            echo "Colors you chose: {$_POST['Colors']}";

        <div  id="container" style="background-color:#FFD700;height:1000px;width:990px;float:right;">
            <iframe src="process.php" name="content" width="1050px" height="1500px" seamless>   </iframe>
        </div>

        <?PHP
        }
        ?>
    </body>
</html>