2010-12-14 2 views
0

궁금하네요, 에서 양식 유효성 검사를 수행하는 short/good 방법이 궁금합니다. JavaScript에서 input-text<select>를 모두 반복하여 선택합니다. 그러나 선택 조건은 2 중에서 선택합니다. 하나만 선택해야합니다.JavaScript - 특정 필드를 통한 양식 유효성 검사 루프

<form id="daform"> 
<input type="text" value="" name="name" id="name" /> 
<input type="text" value="" name="last" id="last" /> 

<select id="choice1" name="choice1"> 
<option>Bye</option> 
<option>Hello</option> 
</select> 

<select id="choice2" name="choice2"> 
<option>Bye</option> 
<option>Hello</option> 
</select> 

<input type="submit" /> 
</form> 

답변

0

jQuery validation plugin을 사용해 보셨습니까?
데모 here을 볼 수 있습니다.

+0

감사합니다. jQuery를 사용하지 않는 것이 좋습니다. – dafont

+0

사용하는 경우 인생이 더 쉬워 질 것이라고 생각합니다. jQuery;) – RSK

0

당신은 정말이에 대한 도움말은 일부 자바 스크립트 툴킷을 사용한다, 그렇지 않은 경우이 도움이 될 :이 선택 상자 중 하나가 선택한 '안녕하세요'값이 있는지 확인합니다

validateSelectChoices = function(){ 
    return document.getElementById('choice1').selectedIndex || document.getElementById('choice2').selectedIndex; 
} 

(유지 Dropdowns는 항상 목록의 첫 번째 옵션 인 'bye'을 기본값으로 사용합니다.

관련 문제