Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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:
XML
<select name="layanan2" id="layanan2" disabled="true">
<option selected="selected">--Pilih--</option>
</select>


and this is code that control level 2 value:
PHP
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 :
PHP
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??
Posted
Updated 31-Aug-13 4:55am
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900