Home > Backend Development > PHP Tutorial > input 之间如何传递数据是在同一页面

input 之间如何传递数据是在同一页面

ringa_lee
Release: 2023-02-28 14:00:01
Original
1972 people have browsed it

input 之间怎么传递数据是在同一页面

本帖最后由 yulelcom2 于 2014-12-12 23:25:43 编辑

input 之间怎么传递数据是在同一页面
怎么把pripath和tfilename2 的数据 传给tfilename 就一个页面

页面提交后tfilename 值得到 pripath和tfilename2 的数据

<input name="tfilename" type="hidden" id="tfilename" value="<?=$pripath?><?=$tfilename2?>">     
      <td height="25" bgcolor="#FFFFFF">根目录</td>
  <input name="pripath" type="text" id="pripath" value="<?=$pripath?>" size="30">
      <input name="tfilename2" type="text" id="tfilename2" value="<?=$tfilename2?>" size="16">
Copy after login

------解决思路----------------------

<script type="text/javascript">
function add(){
document.getElementById(&#39;tfilename&#39;).value = document.getElementById(&#39;pripath&#39;).value + &#39;&#39; + document.getElementById(&#39;tfilename2&#39;).value;
}
</script>
<input name="tfilename" type="hidden" id="tfilename" value="<?=$pripath?><?=$tfilename2?>">     
<td height="25" bgcolor="#FFFFFF">根目录</td>
<input name="pripath" type="text" id="pripath" value="<?=$pripath?>" size="30">
<input name="tfilename2" type="text" id="tfilename2" value="<?=$tfilename2?>" size="16">
<input type="button" name="b1" onclick="add()" value="传递" >
Copy after login

点传递按钮。
------解决思路----------------------

<?php
header("Content-type: text/html; charset=utf-8");
$pripath = "c:\\windows\\";
$tfilename2 = "test.txt";
?>
<form action="" method="post" name="file_form" id="file_form"/>
<table>
    <tr>
 <input name="tfilename" type="hidden" id="tfilename" value="<?php echo $pripath; ?><?php echo $tfilename2;  ?>" />     
      <td height="25" bgcolor="#FFFFFF">根目录</td>
      <input name="pripath" type="text" id="pripath" value="<?php echo $pripath; ?>" size="30">
      <input name="tfilename2" type="text" id="tfilename2" value="<?php echo $tfilename2; ?>" size="16">
      </tr>
      <tr>
          <td><input type="submit" name="submit"/></td>
      </tr>
</table>
</form>
<?php
if (isset($_POST[&#39;submit&#39;])) {
    $pripath = $_POST[&#39;pripath&#39;];
    $pripath = (!get_magic_quotes_gpc()) ? addslashes($pripath) : $pripath;
    $tfilename2 = $_POST[&#39;tfilename2&#39;];
    $tfilename2 = (!get_magic_quotes_gpc()) ? addslashes($tfilename2) : $tfilename2;
    $str = "<script>\r\n";
    $str .= "document.getElementById(&#39;tfilename&#39;).value = &#39;{$pripath}{$tfilename2}&#39;;\r\n";
    $str .= "document.getElementById(&#39;pripath&#39;).value = &#39;{$pripath}&#39;;\r\n";
    $str .= "document.getElementById(&#39;tfilename2&#39;).value = &#39;{$tfilename2}&#39;;\r\n";
    $str .=  "</script>\r\n";    
    echo $str;
}
?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template