0

forms在一个页面中有很多,有一个按钮可以打开一个隐藏的文本编辑器,目的是根据 user_id 更新文本文件,所以我遍历所有用户并获得其中的许多:

<form action="admin/edittoken.php" method="POST">
    <td><a id="'.$result[0]['user_id'].'" onclick="toggle_visibility(\'feedDiv\');">
        <button onclick="toggle_visibility(\'feed\');" type="button">Feed
        </button><a/></td>
    <td><button class="btn btn-default" type="submit" name="password" >Apply Changes</button></td>
    <td><input name="first_name" class="smallInput" value="'.$result[0]['first_name'].'" type="text" /></td>
</form>

正如您所看到的,当我单击此链接时,每个表单都有一个我显示一个 id =feedDiv

<a id="'.$result[0]['user_id'].'" onclick="toggle_visibility(\'feedDiv\');">

的 id<a>是用户 id,使用该数据我可以提取正确的 txt 文件进行编辑

所以我的目标是:

  1. 获取请求显示 div 时单击的链接的 ID(user_id)
  2. 将该 id 放在 php 之间,以便 PDO 查询并显示正确的 txt 文件

这是php

<div id="feedDiv">
    <form method="POST" action="admin/edittoken.php">
        <textarea id="feed" name="information">
            <?php $user=/ /the a Link Clicked Id Value is the user_id //need help
            here $filename=/ /equal to the PDO Result to get the right text file $handle=f
            open($filename, "r"); $contents=f read($handle, filesize($filename)); fclose($handle);
            echo $contents; ?>
        </textarea>
        <button class="btn  btn-primary yellow" type="submit" name="feed">Send Feed</button>
    </form>
</div>

到目前为止的Javascript...

function toggle_visibility(id) {
    var e = document.getElementById(id);
    if (e.style.display == 'block') e.style.display = 'none';
    else e.style.display = 'block';
}

JSFIDDLE:http: //jsfiddle.net/EC6b4/1/

4

1 回答 1

0
<a id="'.$result[0]['user_id'].'" onclick="toggle_visibility(\'feedDiv\', this.id);">


function toggle_visibility(id, user_id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';

$.post("userdetail.php", { userid: user_id },
  function(data){
    $('#'+id).html(data);
  });

}

userdetail.php 包含:

<form method="POST" action="admin/edittoken.php"> 
    <textarea id="feed" name="information">
    <?php
            $user = $_POST['userid']//the a Link Clicked Id Value is the user_id //need help here
            $filename = //equal to the PDO Result to get the right text file
                    $handle = fopen($filename, "r");
            $contents = fread($handle, filesize($filename));
            fclose($handle);
            echo $contents;
        ?>
        </textarea>
        <button class="btn  btn-primary yellow" type="submit" name="feed"  >Send Feed</button>  
        </form>

///// 你的占位符就像

<div id="feedDiv" ></div>
于 2013-08-29T04:31:18.747 回答