楼主的函数是php服务端的,onclick是客户端调的js,当然不可能这样调起来啊!
正常的做法是客户端的js里封装一个ajax的方法,用来触发服务端的php代码。

解决方案 »

  1.   

    汗你错的太厉害了啊。。你的函数都写错了。你这完全把php和js搞混了吧。<?
    function displaytr()
    {
    if(form.law_table.value==1)
    {
    $sql="select * from table where id=8";
    $res=mysql_query($sql);
    $row=mysql_fetch_array($res);
    print("<script>alert(\"$row[name]\")</script>");
    }
    else
    {
    print("<script>alert(\"test\")</script>");
    }
    }
    ?>你这到底是什么的函数啊?如果是一个js函数,js外面声明
    <script language='javascript'>
    function xxxx()
    {
    }
    </script>
    而你这个呢?function xxx(){<script>alert();</script>
    }这也错的太离谱了
      

  2.   

    当然没反应啦,ONchange掉用的应该是javascript函数呀,怎么会是PHP函数呢?
      

  3.   

    哦,我明白了,
    但是在js中,我怎么才能把mysql中的数据调出来呢?
      

  4.   

    这个乱是乱是点,不过可以用。LZ不妨看看。
    ===============================================
    <?
    $query3="select * from product where p_ifshow<>8 order by  p_order asc ";
    $result3=mysql_query($query3);
    $num3=mysql_num_rows($result3);
    ?>
    <script language = "JavaScript">
    var onecount;
    subcat = new Array();
            <? for($count=1;$count<=$num3;$count++){
    $row3 = mysql_fetch_array($result3);
    $id=$row3["id"];
    $p_bigclassid=$row3["p_bigclassid"];
    $p_title=$row3["p_title"];
    ?>
    subcat[<? echo $count;?>] = new Array("<? echo $p_title; ?>","<? echo $p_bigclassid; ?>","<? echo $p_title; ?>");
            <? } ?>
    onecount=<? echo $count;?>;function changelocation(locationid)
        {
        document.myform.SmallClassName.length = 1; 
        var locationid=locationid;
        var i;
    //alert (locationid);
        for (i=1;i < onecount; i++)
            {
                if (subcat[i][1] == locationid)
                { 
                    //alert (onecount+subcat[i][1]);
    document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
                }        
            }
        }    
    </script><select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)">
                          <option value=0>aa</option>
    </select><select name="SmallClassName">
                          <option value="不指定小类>bb</option>
                          
                        </select>