2010-07-22 3 views
0

나는 그랬다. 내 웹 응용 프로그램 중 하나에 대한 요구 사항 :텍스트 필드를 채우는 라디오 버튼

내 HTML 표에서 일부 열은 텍스트 입력란으로 사용자 입력이 필요합니다. 텍스트 필드 옆에있는 테이블의 특정 조건을 충족하는 행을 채우는 라디오 버튼이 각 행에 필요했습니다.

여기 (ID applyNewContact0와) 행 1 라디오 버튼이 체크 된 경우, 그때 Inst.ID 모든 행 (그들의 newContact, newContactPhone, newContactEmail)를 채울 원,

<td> <input type="text" id="newContact<%=rCount %>" name="newContact"> 
    <br> 
    <input type="radio" id="applyNewContact<%=rCount %>" name="applyNewContact" onchange=..some js function here..>  
    <label for="applyNewContact<%=rCount %>">Apply Contact to all cases @Inst.ID</label> 
    </td> 
    <td align="center"> <input type="text" id="newContactPhone<%=rCount %>" name="newContactPhone"></td> 
    <td align="center"> <input type="text" id="newContactEmail<%=rCount %>" name="newContactEmail"></td> 

그래서 내 코드입니다 (내 테이블 열 중 하나) row1과 동일

jQuery 또는 Javascript를 사용하여 어떻게해야합니까?

감사합니다,이 같은
Pritish

답변

1

무엇인가?

var $radios = $(':radio[id^=applyNewContact]').change(function() { 
    var id = $radios.index(this); 
    $('#newContact' + id).val(inst[id].newContact); 
    $('#newContactPhone' + id).val(inst[id].newContactPhone); 
    $('#newContactEmail' + id).val(inst[id].newContactEmail); 
}); 

이것은 가정합니다. rCount은 0+ 카운터입니다. 교체하지 않을 경우

var id = this.id.match(/applyNewContact(.+)/)[1];