2011-07-03 16 views
0

양식의 유효성을 검사해야합니다. jQuery 유효성 검사 플러그인을 사용하고 있지만이 작업을 수행 할 수 없습니다.jQuery 유효성 검사 플러그인 확인란 확인

<form id="form1" name="form1" action=<?=$_SERVER['PHP_SELF'];?> method="POST"> 
<div> 
     <h3>Cardio-Pulmonary System</h3> 
     <div style="border: medium none;display: inline;padding: 0;text-align:left"> 
     <h4>1. Do you have, or have you had, or do you take medications for?</h4> 
     <label><input class="checkbox" type="checkbox" value="none" name="q1[]" />no/or none of the below</label> 
     <p><input class="checkbox" type="checkbox" value="q1-1" name="q1[]" />heart disease (please specify) 
     <input class="checkbox" type="text" id="text" name="q1-1" value="" /></p> 
     <p><input class="checkbox" type="checkbox" value="high blood pressure" name="q1[]" />high blood pressure</p> 
     <p><input class="checkbox" type="checkbox" value="high cholesterol" name="q1[]" />high cholesterol</p> 
     <p><input class="checkbox" type="checkbox" value="diabetes" name="q1[]" />diabetes</p> 
     <p><input class="checkbox" type="checkbox" value="q1-2" name="q1[]" />lung disorder (eg asthma, emphysema) 
     <input class="checkbox" type="text" id="text" name="q1-2" value="" /></p> 
     <p><input class="checkbox" type="checkbox" value="other cardiac problem" name="q1[]" />other cardiac problem (include pacemaker)</p> 

     <h4>2. Do you have a family history of?</h4> 
     <p><input type="checkbox" value="none" name="q2[]" />no/or none of the below</p> 
     <p><input type="checkbox" value="heart murmur" name="q2[]" />heart murmur</p> 
     <p><input type="checkbox" value="valve defect" name="q2[]" />valve defect</p> 
     <p><input type="checkbox" value="racing heart" name="q2[]" />racing heart</p> 
     <p><input type="checkbox" value="irregular beats" name="q2[]" />irregular beats</p> 
     <p><input type="checkbox" value="angina" name="q2[]" />angina</p> 
     <p>other<br/><input type="text" id="text" value="" name="q2[]" /></p> 

     <h4>3. Have you ever been told that you have heart problems? Eg</h4> 
     <p><input type="checkbox" value="none" name="q3[]" />no/or none of the below</p> 
     <p><input type="checkbox" value="heart disease" name="q3[]" />heart disease</p> 
     <p><input type="checkbox" value="high blood pressure" name="q3[]" />high blood pressure</p> 
     <p><input type="checkbox" value="high cholesterol" name="q3[]" />high cholesterol</p> 
     <p><input type="checkbox" value="diabetes" name="q3[]" />diabetes</p> 
     <p><input type="checkbox" value="stroke" name="q3[]" />stroke</p> 

     <h4>4. Do you have, or have you experienced?</h4> 
     <p><input type="checkbox" value="none" name="q4[]" />no/or none of the below</p> 
     <p><input type="checkbox" value="epilepsy" name="q4[]" />epilepsy</p> 
     <p><input type="checkbox" value="fainting" name="q4[]" />fainting</p> 
     <p><input type="checkbox" value="seizures" name="q4[]" />seizures</p> 
     <p><input type="checkbox" value="dizzy spells" name="q4[]" />dizzy spells</p> 
     <p><input type="checkbox" value="convulsions" name="q4[]" />convulsions</p> 

     <h4>5. Have you ever smoked cigarettes?</h4> 
     <p><input type="checkbox" value="q5-1" name="q5[]" />Yes, still do approx <input type="text" name="q5-1" style="width:20px" maxlength="3" /> a day</p> 
     <p><input type="checkbox" value="q5-2" name="q5[]" />Yes, but stopped <input type="text" name="q5-2" style="width:20px" maxlength="3" /> months/<input type="text" name="q5-3" style="width:20px" maxlength="3" /> years ago. </p> 
     <p><input type="checkbox" value="never" name="q5[]" />Never</p> 
    </div> 
    </form> 

각 질문에 대해 하나 이상의 확인란을 선택해야하는 이유는 무엇입니까? "당신이 추가 할 수 있습니다, 당신은 HTML 양식을 검증하기 위해 JQuery와 유효성 검사 플러그인을 사용할 수 있으며, 체크 박스를 확인하기

+0

또한 이유는 하나의 오류 메시지가 각 입력 상자의 유효성을 검사해야하는 이유가 무엇인지 알 수 없습니다. –

+0

Jae, 나는 또한 CSS 파일을 사용하여 서식을 입력하는 것이 좋습니다. ID (또는 클래스의) 폼에 대한 체크 박스는 유효성 확인에도 도움이됩니다 – Brad

답변

0

//test9.favstay.com/form.php :

은 내 양식 ... HTTP입니다 사용자 지정 선택기 "를 유효성 검사 옵션에 추가하십시오. 각각의 체크 박스 (Q4, Q5 등)에 대한 ID를 추가 예를 here

1

를 사용하여 최소 및 최대 길이

<input type="checkbox" value="palin" name="upd" id="upd"/> 
</p> 
<p> 
<label for="fox">Fox</label> 
<input type="checkbox" value="fox" name="upd" id="upd" /> 
</p> 
<p> 
<label for="left">Left</label> 
<input type="checkbox" value="left" name="upd" id="upd" /> 
</p> 

검증

$("#upd").rules("add", { 
     required: true, 
     minlength: 1, 
     maxlength: 1, 
    messages: { 
     required: "Please pick a category", 
     minlength: jQuery.format("Please, Check at least one box"), 
     maxlength: jQuery.format("Please, You checked too many boxes"), 
    } 
}); 

을 확인, 당신의 Q3를 대체, Q4 등 어디 #upd있다. 이 기능을 사용자의 요구에 맞게 조정하십시오.

+1

-1 - 같은 ID로 페이지에 여러 요소를 가질 수 없습니다 – timbrown

관련 문제