2013-10-24 65 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

相關問題