简体   繁体   English

需要使用javascript的php帮助

[英]need help on php with javascript

I need help on some update like function: 我需要一些有关功能的更新的帮助:

<html>
$result = mysql_query("SELECT *FROM tbl_a LEFT JOIN tbl_b lass ON tbl_b.b_id=a.class_id LEFT JOIN category ON category.category_id=tbl_a.category_id WHERE list ='{$id}'"); </br>
      while($row = mysql_fetch_array($result)){ 
     $id_list = $row['id']; 
      $name = $row['name'];
      ....
     }
    }
    echo "<script type='text/javascript'>
     var id = document.getElementById('list').value = '.$id_list;'  
     var name = document.getElementById('fname').value ='.$name;'   
    </script> ";
</html>

my problem is that i can retrieve data but it not displaying on my input elements it should be like an update function 我的问题是我可以检索数据,但它不会显示在我的输入元素上,应该像一个更新功能

Quotes, quotes... 引号,引号...

    echo 
    "<script type='text/javascript'>
    var id = '".$id_list."',
    name = '".$name."';

        document.getElementById('list').value = id;  
        document.getElementById('fname').value = name;
    </script> ";

Working example: http://codepad.viper-7.com/3eI3Od 工作示例: http : //codepad.viper-7.com/3eI3Od

You need to call your input elements and then give them the new values instead of setting variables like you are doing. 您需要调用输入元素,然后为它们提供新值,而不是像您那样设置变量。 Remove the "var something =" and just do document.get....... 删除“ var something =“,然后执行document.get.......。

If what you posted is the complete code, then there is no list and fname elements. 如果您发布的是完整的代码,则没有listfname元素。 Better open the page and view the source code to see if you have the right value written into your Javascript. 最好打开页面并查看源代码,以查看是否已将正确的值写入Javascript。

NOTE: 注意:
Remember that if you put your Javascript after the element HTML, Javascript cannot retrieve the element. 请记住,如果将Javascript放在元素HTML后面,则Javascript无法检索该元素。 For example: 例如:

<script>
    document.getElementById('test').value = 'Hello World';
</script>
<input type='text' id='test' value=''>

As you can see, it does not assign value to test element. 如您所见,它不会为test元素分配值。 Solution, 解,

<input type='text' id='test' value=''>
<script>
    document.getElementById('test').value = 'Hello World';
</script>

Put the input before the Javascript. 将输入内容放在Javascript之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM