i’ve trying to generate a form of and when the form checked onClick() event shall enable the select option. Here is my php code :
function generateOption()
{
for($x = 0; $x < 10; $x++)
{
echo "<option value='".$x."'>".$x."</option>";
}
}
function generateForm($I_Id)
{
switch($I_Id)
{
case "I0001":
{
echo "<td><input type='checkbox' name='".$I_Id."' value='".$I_Id."' id='".$I_Id."' onClick='Enable(this,BT)' />";
echo "Binding Tape</td><td>";
echo "<select size='1' name='KuantitiMohon".$I_Id."' id='BT' disabled >";generateOption();echo "</select></td>";break;
}
}
Here is my javascript code:
function Enable(checkB,idE)
{
if(checkB.checked==true)
{
document.getElementById(idE).disabled=false;
}
else
document.getElementById(idE).disabled=true;
}
I’m not very sure what’s the problem, however, in my previous html code, i able to enable the option there and now become unable after i change to php.
You are trying to pass the “object” BT but your intention is to pass the “string” id named BT. You need to add quotes around “BT” like so:
You need to escape the quotes around the onclick so that PHP does not assume it to be the end of your string.