我有一个javascript函数来选择选中的选项来选择表格单元格的内容:
<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>
以下是我正在调用的php函数:
<?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>";
}
?>
当我调用上面的函数时,表单字段的默认值已设置,但onchange
和onclick
javascript函数不起作用。我哪里错了?请帮忙
(***我必须只使用PHP来回应表格)