我知道它可以在PHP中調用javascript函數,它已經工作,但是當我嘗試調用checkSecondValue時,什麼也沒有發生。我已經在調用函數時加入了我的變體。在PHP中調用JS函數
編輯:如果我嘗試在底部調用它而不激活select中的onChange事件,它就不能工作。
<!--<html>
<head>
<script type="text/javascript" src="validation.js"></script>
</head>
</html>
<script src="validation.js" type="text/javascript"></script>
-->
<?php
//retrieve all the bris for the drop down
include '../../inc/database.php';
$res = BbqcDatabase::getInstance()->doQuery('SELECT * FROM T_TOURNOI_BRIS');
$str = "<select name='ddlBrisSelected' id='ddlBrisSelected' onChange='checkSecondValue()'>";
$bris = ($_GET['bris']);
if($bris == 4)
{
$bris2 = "autre";
}
if($bris == null)
{
$str .= "<option value='' selected></option>";
}
else
{
$str .= "<option value=''></option>";
}
$i = 0;
while($data = mysql_fetch_assoc($res))
{
if($data['F_BRISID'] == $bris)
{
$str .= "<option value='" . $data['F_BRISID'] . "' selected '>" . $data['F_BRISTITLE'] . "</option>";
}
else
{
$str .= "<option value='" . $data['F_BRISID'] . "'>" . $data['F_BRISTITLE'] . "</option>";
}
}
if($bris2 == "autre")
{
$str .= "<option value='autre' selected>Autre</option>";
}
else
{
$str .= "<option value='autre'>Autre</option>";
}
$str .= "</select>";
echo $str;
if(is_numeric($bris))
{
/* echo "<SCRIPT language=\"JavaScript\" SRC=\"validation.js\">checkSecondValue();</SCRIPT>"; */
/* echo "<script> checkSecondValue();</script>"; */
/* echo "<script type=\"text/javascript\">checkSecondValue();</script>"; */
/* echo '<script type="text/javascript">', 'checkSecondValue();', '</script>'; */
/* echo "<SCRIPT LANGUAGE='javascript'>checkSecondValue();</SCRIPT>"; */
}
?>
'checkSecondValue()'定義在哪裏? – mellamokb 2011-03-04 18:34:46
這不可能在PHP中調用JS函數。在學習如何做之前,先了解你實際嘗試做什麼。 – Jon 2011-03-04 18:35:27
在一個單獨的js文件中調用validation.js – 2011-03-04 18:35:55