【发布时间】:2015-05-12 11:12:03
【问题描述】:
我的 html 表单有问题。现在我处于以下阶段:我需要选择一个国家,如果我选择印度,我将获得印度的州列表,或者如果将下拉列表更改为瑞士,我将获得用于键入状态的文本框。如下图。
在图片中,我选择了印度,并选择了古吉拉特邦。
这里我再次选择了瑞士并声明我输入为伯尔尼
我的问题是如果我将国家从瑞士更改为加拿大。我输入为“bern”的状态保持不变,如第三张图片所示。所以我需要将该字段设为空。当我选择不同的国家时,我需要将我的州字段设为空,所以请帮助我[我正在使用 html、js 和 php]。
脚本:
function ShowHideStateDetails()
{
if(document.getElementById("ai_country").value == 'India')
{
document.getElementById("ai_other_state").style.display='none';
document.getElementById("ai_ind_state").style.display='';
}
else
{
document.getElementById("ai_ind_state").style.display='none';
document.getElementById("ai_other_state").style.display='';
}
}
HTML:
<!-- country -->
<label for="ai_country">Country</label>
<input id='ai_country' onchange="ShowHideStateDetails()" >
<!-- State -->
<label for="ai_state">State<</label>
<input type="text" id="ai_other_state">
<select id="ai_ind_state" style="display: none;">
<option value="">Select</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
<option value="Daman and Diu">Daman and Diu</option>
<option value="Delhi">Delhi</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Uttaranchal">Uttaranchal</option>
<option value="West Bengal">West Bengal</option>
</select>
提前致谢
【问题讨论】:
标签: javascript php html