I make 2 level drop down list using javascript and php and that work fine..
My problem is I cannot figure out how to make :
1. the level 2 drop down list will disabled by default (this work)
2. when the level 1 value change, the level 2 become enable and show the value (this I cannot figure out)
this is the view code:
<select name="layanan2" id="layanan2" disabled="true">
<option selected="selected">--Pilih--</option>
</select>
and this is code that control level 2 value:
if ($layanan2_id > 0) {
echo ""<script type=\"text/javascript\">document.getElementById('layanan2').disabled=false;</script>";
echo "<select id='layanan2'>";
while($row_layanan2 = mysql_fetch_array($result_layanan2))
{
echo "<option value='".$row_layanan2['id']."'>".$row_layanan2['kategori']."</option>";
}
echo "</select>";
}
else {
echo "<select id='layanan2'>";
echo"<option value=''>--Pilih--</option>";
echo "</select>";
}
The above code can make level 2 become enable but don't show the value..
If I remove the code :
echo "<script type=\"text/javascript\">document.getElementById('layanan2').disabled=false;</script>";
You can see the level 2 value inside the disabled drop down box..
So I guess that the problem is in my js code inside the echo but I don't know how to fix it..
Can anyone show me a way please??