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)