douzhi6160 2016-10-09 23:57
浏览 55

无法从PHP调用onchange和onclick JavaScript函数

I have a javascript function to choose the selected option to chnage the content of a table cell :

<script>
function getValue(selValue) {
if(selValue == "Apple")
    document.getElementById("fruittype").innerHTML = "A";

if(selValue == "Banana")
    document.getElementById("fruittype").innerHTML = "B";

if(selValue == "Orange")
    document.getElementById("fruittype").innerHTML = "C";
}
</script>

And below is my php function that I am calling :

<?php
function retainFormOnLoad($fruit)
{           
    echo "<form d='form1' name='form1' method='post' >";
    echo "<table>";
    echo "<tr>
        <td>Congress Database</td> 
        <td style='text-align: center;'>
        <select name='fruit' id='fruit' onchange='getValue(document.getElementById('fruit').value)'>
            <option value='-1' selected disabled>Select your option</option>
            <option value='Apple' ".(($fruit=='Apple')?'selected':'')." >Apple</option>
            <option value='Banana' ".(($fruit=='Banana')?'selected':'')." >Banana</option>
            <option value='Orange' ".(($fruit=='Orange')?'selected':'')." >Orange</option>              
        </select>
     </td>
  </tr>";
  echo "<tr>
     <td id='fruittype'>A</td>
     <td>Always Good!</td>
  </tr>";
 echo "<tr><td colspan='2'><input type='reset' value='Clear' onclick='reset()'></td></tr>
</table></form>";
}
?>

When I call the above function, the default values of form fields are set but the onchange and onclick javascript functions do not work. Where am I going wrong? Please help

(***And I have to use PHP only to echo the form)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝