0
我正在嘗試隱藏單選按鈕「否」已選中並且選中「是」時字段集頁面加載時的字段集元素應該出現。目前,如果用戶選中「否」,並且/或者顯示用戶選中「是」,則該字段集隱藏。但是我希望字段集在頁面加載時被隱藏,或者如果已選中「否」,並且選中「是」後應顯示字段集及其內容。在頁面加載時或當單選按鈕選項已被選中時隱藏字段集
hide_show_field.js
function ToggleDisplay(Section, boolHide) {
if (boolHide) {
Section.style.display = "none";
}
else {
Section.style.display = "block";
}
}
function disableElement(element, boolHide)
{
var input = document.getElementById(element).getElementsByTagName("input");
for(var i = 0; i < input.length; i++)
{
input[i].removeAttribute("disabled");
}
}
function hideShowElement(CurrentSection, OtherSection, DisableSection)
{
var sectionVal = CurrentSection.value;
if (sectionVal == 'No') {
ToggleDisplay(OtherSection, true);
disableElement(DisableSection, "true");
}
else {
ToggleDisplay(OtherSection, false);
disableElement(DisableSection, "false");
}
}
form.php的
<p class="text">
<label for="Transferred">Transferred</label>
<input type="radio" name="transferred" value="Yes" onchange="hideShowElement(this, mydiv, 'optionGroup');">Yes
<input type="radio" name="transferred" value="No" onchange="hideShowElement(this, mydiv, 'optionGroup');">No
</p>
</div>
</fieldset>
<fieldset class="group" id="optionGroup">
<legend>Transfer</legend>
<div id="mydiv">
<div class="col">
<p class="text">
<label for="Transferred To">Transferred To</label>
<select name="transferTo">
<option value="Select Station"></option>
<?php include('php/selectlocation.php'); ?>
</select>
</p>
<p class="text">
<label for="Date Transferred">Date Transferred</label>
<input type="date" name="dateTransferredTo" id="datepicker1" placeholder="YYYY-MM-DD" >
</p>
</div>
<div class="col">
<p class="text">
<label for="Transferred From">Transferred From</label>
<select name="transferFrom" >
<option value="0"></option>
<?php include('php/selectlocation.php'); ?>
</select>
</p>
<p class="text">
<label for="Date Transferred">Date Transferred</label>
<input type="date" name="dateTransferredFrom" id="datepicker2" placeholder="YYYY-MM-DD" >
</p>
<p class="text">
<label for="Rank Transferred With">Rank Transferred With</label>
<select name="rankTransferredWith">
<option value="0"></option>
<?php include('php/selectranks.php'); ?>
</select>
</p>
</div>
</div>
</fieldset>
有人可以提供一些幫助,請
好吧會嘗試 – user2538755