2013-10-24 66 views
-1

我有不同的单选按钮,每个按钮都与我的表单上的文本框相关联。用户一次只能选择一个单选按钮并提交表单。但是,有时用户会在一个文本框中输入一个单选按钮的数据,然后选择其他选项并在其中输入文本框数据。目前它保留两个文本框中的数据并提交它们。保留其单选按钮被点击的文本框的值

有什么办法可以清除数据并只保留最后点击的数据?就像一个onclick事件,它清除除了选中的其他单选按钮之外的所有数据。

只是一个快速静态示例代码:

<form class="form-horizontal" id="whereEntry" method='post' action=''> 
    <input type="radio" name="formOption" id="radio1210" value="1210" checked="checked">Waiting on Approval<br> 
    Comment:<input type="text" name="Comment"><br> 

    <input type="radio" name="formOption" id="radio1211" value="1211" checked="checked">Waiting on Authorization<br> 
    Comment:<input type="text" name="Comment"> 

    <input type="Submit" value="Submit">Submit 
</form> 

文本框的值被点击单选按钮时被显示。所以,如果我点击一个单选按钮,并在评论文本框中输入一个值,然后点击另一个单选按钮,则两个评论框值都将保留。

+1

向我们展示什么ü试过至今。 –

+1

你可以发布你的HTML吗? – Satpal

+0

让我们看看表格 – tymeJV

回答

0

像这样

HTML标记

<input type="radio" id="radio1" name="gender"/>Male 
<input type="text" id="txt1"> 
<br /> 
<input type="radio" id="radio2" name="gender"/>FeMale 
<input type="text" id="txt2"> 

jQuery的

$("input:radio").click(function(){ 
    $("input:text").not($(this).next()).val(""); 
}) 

Live Demo

相关问题