JAVASCRIPT:传递的参数是“未定义”

I'm creating a page that should read data from the database, display it as a table, and allow row-wise editing of the entries (using AJAX calls). Here are brief code snippets where the problem comes -

Javascript:

function editParam(bname, button) {
 alert(bname); //this part doesn't happen, the error on console comes up before it
 tr = button.parentNode;
 while (tr && tr.nodeName.toUpperCase() !== "TR" && tr.nodeName.toUpperCase() !== "BODY") {
    tr = tr.parentNode;
 }
 if (!tr || tr.nodeName.toUpperCase() !== "TR") {
    return; 
 }
 //some more code
}

PHP:

//get $row_users['Name']
while ($row_users = mysqli_fetch_array($results)) {
 echo "<form method='POST'> //some <tr><td></td></tr>
 <button onclick='editParam(".$row_users['Name'].", this)'>Edit</button>
 </form>";
}

My data in the column Name is like "B1", "C2", etc.

Error onclick of button : B1 is not defined.

While running the code for other text or numbers, it worked fine. So I understand that my problem has to do with the datatype. However, I do not know how resolve the same.

Any suggestions would be much appreciated, thanks!

查看全部
dsqtl335227
dsqtl335227
2014/10/11 13:16
  • php
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复