我创建一个form
w /单选按钮进行选择,以便隐藏其他输入字段。
我只想要,如果输入字段隐藏值将变为默认值。
的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>
答案 0 :(得分:1)
您可以做的是保存输入的默认值,然后在需要时将其插回。
例如:
var inputVal = document.getElementById('input1').value;
//When input value is hidden, insert value
var hiddenInput = document.getElementById('input1').value = inputVal;