duanniu3385 2016-04-09 17:32
浏览 34

JS未能传递价值?

I have the following code which is updating a form on click. When populating title and content, it works fine. When I added startDate nothing populates. Im assuming something in my syntax is wrong but all the logic looks correct to me. Am I missing something?

        <script type="text/javascript">
            function changeText(title, content, startDate){
                window.alert("test");
                document.getElementById('startDate').value = document.getElementById(startDate).getAttribute('data-content');
                document.getElementById('content').value = document.getElementById(content).getAttribute('data-content');
                document.getElementById('title').value = document.getElementById(title).getAttribute('data-content');      
       }
       </script>
       <?php
       foreach ($announcement as $row){ //Displays title, startDate, endDate from announcement table from database 
       $tile = ($row["announcementID"] ."t");
       $cont = $row["announcementID"];
       $startDate = ($row["announcementID"] ."s");


       echo "<h2 style=width:auto;padding:8px;margin-top:-30px;font-size:18px;><a style=text-decoration:none;color:#c4572f; >".$row["title"]."</a></h2><br>";
       echo "<p style=padding-top:10px;>".$row["content"]."</p><br>";
       echo "<p style=font-size:10px;>Posted: ".$row["startDate"]."</p><br>";
       echo '<input id="'.$tile.'" data-content="'.$row["title"].'" type=button class=test onclick="changeText(id, '.$cont.', '.$startDate.');" value="Edit">';
       echo '<p id="'.$cont.'"  data-content="'.$row["content"].'">test</p>';
       echo '<p id="'.$startDate.'"  data-content="'.$row["startDate"].'">startDate</p>';
       echo "<h5 style=line-height:2px;margin-top:-15px;><p>_____________________________________</p></h5><br>";
      }

        ?>
  • 写回答

1条回答 默认 最新

  • dongyimeng3764 2016-04-09 18:18
    关注

    I found the solution after some more testing. JS didnt approve of the variable names with letters attached. After editing that variable names the code worked fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题