我的页面上有四个单选按钮。三个单选按钮的值是预定义的。
我想通过在它前面提供文本框来自定义第四个单选按钮。如果用户选择第四个单选按钮并且该值作为单选按钮值发送,则用户必须填写文本框。
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Donation:
<input type="radio" name="donation" <?php if (isset($donation) && $donation=="20,000") echo "checked";?> value="20,000">20,000
<input type="radio" name="donation" <?php if (isset($donation) && $donation=="10,000") echo "checked";?> value="10,000">10,000
<input type="radio" name="donation" <?php if (isset($donation) && $donation=="5,000") echo "checked";?> value="5,000">5,000
<input type="radio" name="donation" <?php if (isset($donation) && $donation=="$custom") echo "checked";?> value="$custom"><input type="text" name="custom" value="<?php echo $custom;?>">Not less than Rs. 3000
<span class="error">* <?php echo $donationErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
<?php
echo "<h2>Your Input:</h2>";
echo "<br>";
echo $donation;
?>
答案 0 :(得分:2)
<强> HTML 强>
<input type= "radio" name ="radiostemp" value="" rel=""/>
<input type= "radio" name ="radiostemp" value="" rel=""/>
<input type= "radio" name ="radiostemp" value="" rel=""/>
<input type= "radio" name ="radiostemp" value="" rel="attach" />
<input type="text" value="" id="testtype" />
<强>的JavaScript 强>
$(document).ready(function(){
$("input[type=radio]").change(function(){
if($(this).attr("rel") == "attach")
{
$(this).val($("#testtype").val());
}
});
$("#testtype").change(function(){
$("input[type=radio]:eq(3)").val($(this).val());
});
});