首页 > 解决方案 > document.getElementById 未定义。敬请期待

问题描述

我整天坐在电脑前,找不到错误的原因。我的问题是我无法从该字段中获取值。我需要一个模式窗口来显示来自该行的数据。然后他想将其发送到基地,但这是另一回事请看我的代码并说出问题所在。

    <?php 
session_start();
require_once "db.php";
?>
<html>  
 <head>  
          <title>Lista użytkowników</title>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
          <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

          <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap.min.js"></script>


    </head>  
    <body>  
  <div class="container">  
   <br />  
   <br />  
   <br />  
            <div class="row" method='POST'>  
    <h3 align="center">Lista użytkowników</h3><br />  
    <form action="" method="post">
    <table id="editable_table" class="table table-bordered table-striped table-hover">
     <thead>
      <tr>
       <th>ID</th>
       <th>Login</th>

       <th>Imię</th>
       <th>Nazwisko</th>
       <th>Email</th>
       <th>Telefon</th>
       <th>Stanowisko</th> 
       <th>NR_pracownika</th>
       <th>Upranienia</th>
       <th>Opcje</th>
     </tr>
     </thead>
     <tbody>
<?php 
if ($mysqli->connect_errno!=0){
  echo "Error".$mysqli->connect_errno;
}else{
$sql ="SELECT * FROM uzytkownicy ORDER BY id ";
if ($result = @$mysqli->query($sql)){
      $_SESSION['zalogowany'] = true;


      while($row = mysqli_fetch_array($result))
     {
      $_SESSION['log_'. $row['id']] = $row['login'];

?>


      <tr>
      <td method='POST' name ="id_<?=$row['id']?>" id="id_<?=$row['id']?>" value="<?=$row['id']?>"  class=" orm-control"/> <?=$row['id']?></td>
      <td method='POST' name="log_<?=$row['id']?>" id="log_<?=$row['id']?>" value="<?=$row['login']?>" class=" orm-control"/> <?=$row['login']?></td>
      <td method='POST' name="imi_<?=$row['id']?>" id="imi_<?=$row['id']?>" value="<?=$row['imie']?>" class=" orm-control"/> <?=$row['imie']?></td>
      <td method='POST' name="naz_<?=$row['id']?>" id="naz_<?=$row['id']?>" value="<?=$row['nazwisko']?>" class=" orm-control"/> <?=$row['nazwisko']?></td>
      <td method='POST' name="ema_<?=$row['id']?>" id="ema_<?=$row['id']?>" value="<?=$row['email']?>" class=" orm-control"/> <?=$row['email']?></td>
      <td method='POST' name="tel_<?=$row['id']?>" id="tel_<?=$row['id']?>" value="<?=$row['telefon']?>" class=" orm-control"/> <?=$row['telefon']?></td>
      <td method='POST' name="sta_<?=$row['id']?>"  id="sta_<?=$row['id']?>" value="<?=$row['stanowisko']?>" class=" orm-control"/> <?=$row['stanowisko']?></td>
      <td method='POST' name="nr_<?=$row['id']?>" id="nr_<?=$row['id']?>" value="<?=$row['nr_pracownika']?>" class=" orm-control"/> <?=$row['nr_pracownika']?></td>
      <td method='POST' name="ran_<?=$row['id']?>" id="ran_<?=$row['id']?>" value="<?=$row['ranga']?>" class=" orm-control"/> <?=$row['ranga']?></td>
      <td>  

        <button type="button" id="<?=$row['id']?>" onClick="reply_click()"  class="glyphicon glyphicon-pencil" data-toggle="modal" data-target="#myModalEdit"  ></button>


      </td>

      </tr>
      </form>



    <?php  ;
     }

      //header('Location: ../workshop.php');
    }
    else{
     // header('Location: ../index.php');

    }

}




?>

  <!-- Modal -->
<div id="myModalEdit" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-body" style="padding:40px 50px;">
          <form role="form">
<h4 align="center">Zmiana danych dla </h4> <h3 id="dozmiany" align="center"> dfhdyjd</h3>
            <div class="form-group">
              <label for="id"><span class="glyphicon glyphicon-user"></span> id</label>
              <input type="text" class="form-control" id="usrname" value='<?php $aaaa ?>'>
            </div>

            <div class="form-group">
              <label for="usrname"><span class="glyphicon glyphicon-user"></span> Username</label>
              <input type="text" class="form-control" id="usrname" value='name'>
            </div>
            <div class="form-group">
              <label for="psw"><span class="glyphicon glyphicon-eye-open"></span> Password</label>
              <input type="text" class="form-control" id="psw" placeholder="Enter password">
            </div>

              <button type="submit" class="btn btn-success btn-block"><span class="glyphicon glyphicon-pencil"></span> Zmien</button>
          </form>
        </div>
        <div class="modal-footer">


        </div>
      </div>
    </div>

  </div>
 </tbody>
</body>
</html>
<script language="javascript">

function reply_click()
{

  var  rrr = event.srcElement.id;
   alert(document.getElementById("log_1").value);
   var ll = "echo $_SESSION['log_" + rrr +" '];";

    document.getElementById("usrname").value = "<?php echo $_SESSION['log_1'];?>";
    document.getElementById("dozmiany").innerHTML = document.getElementById("log_1").value;

  }
</script>

请查看我的代码并说出问题所在。

标签: javascript

解决方案


我自己找到了答案

我想从表中下载数据,所以我使用查询....

document.getElementById("log_1").value;

是错误的,措辞应该是这样......

document.getElementById("myTable_U").rows[rrr].cells.item(1).innerHTML

推荐阅读