如何使用javascript更改php输入中的禁用属性? [英] how change disabled property in php input using javascript?

查看:87
本文介绍了如何使用javascript更改php输入中的禁用属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript和php制作2级下拉列表并且工作正常..

我的问题是我无法弄清楚如何制作:

1.默认情况下将禁用2级下拉列表(此工作)

2.当1级值更改时,级别2变为启用并显示值(这是我无法弄清楚的)



这是查看代码:

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>





这是控制2级值的代码:



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>";
}





以上代码可以使2级变为启用但不显示值..

如果我删除代码:



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>";



您可以在禁用的下拉框中看到第2级值。

所以我猜这个问题在我的js代码内回声,但我不知道如何解决它..



有人能告诉我一个方法吗?


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??

推荐答案

layanan2_id> 0){
echo < script 类型 = \ text / java script \ > document.getElementById(' layanan2')。disabled = false ; < / script > ;
echo< 选择 id =' layanan2' > ;

while(
layanan2_id > 0) { echo ""<script type=\"text/javascript\">document.getElementById('layanan2').disabled=false;</script>"; echo "<select id='layanan2'>"; while(


row_layanan2 = mysql_fetch_array(
row_layanan2 = mysql_fetch_array(


result_layanan2))
{
echo < 选项 ='
result_layanan2)) { echo "<option value='".


这篇关于如何使用javascript更改php输入中的禁用属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆