1
我創建了一個form
w /單選按鈕來選擇,以便其他輸入字段將隱藏。javascript:輸入字段隱藏時回到默認值
我只是想,如果輸入字段隱藏值將變成默認值。
的JavaScript
<script>
function showhidediv(rad)
{
var rads = document.getElementsByName(rad.name);
document.getElementById('one').style.display = (rads[0].checked) ? 'block' : 'none';
document.getElementById('two').style.display = (rads[1].checked) ? 'block' : 'none';
document.getElementById('three').style.display = (rads[2].checked) ? 'block' : 'none';
}
</script>
形式
<form action="aef.php" method="post">
<label>Date</label><br />
<input type="text" value="<?php echo date('Y-m-d'); ?>" name="date" /><br /><br />
<input type="radio" name="transtype" value="0" onclick="showhidediv(this);" checked /> LBC Payment
<input type="radio" name="transtype" value="1" onclick="showhidediv(this);" /> Additional Funds
<input type="radio" name="transtype" value="2" onclick="showhidediv(this);" /> miscellaneous expense
<br /><br />
<div id="one">
<label>LBC Tracking No.</label><br />
<input type="text" value="" name="lbc" /><br /><br />
<label>Transaction Code</label><br />
<input type="text" value="" name="code" id="code" /><br /><br />
<label>Credit Amout</label><br />
<input type="text" name="credit_amount" />
<br /><br /><p>Available funds : <?php echo $ab; ?></p>
</div>
<div id="two" class="divhide">
<label>Debit Amout</label><br />
<input type="text" name="debit_amount" />
</div>
<div id="three" class="divhide">
<label>Expenses Description</label><br />
<input type="text" id="expenses" value="" name="description" /><br /><br />
<label>miscellaneous expense</label><br />
<input type="text" name="credit_amount2" />
<br /><br /><p>Available funds : <?php echo $ab; ?></p>
</div>
<br /><br />
<input type="submit" value="Add Expenses" name="submit" />
</form>