I am trying to verify a form that has multiple check boxes, and when the "other" check box is checked and the "other_text" input has nothing in it. I need an error to fire asking to input the other text. here is the current verification that does not work with my "other" check box.
}else if(question_pos==24){
if((!$('#followup_six_45_physician').prop('checked') && !$('#followup_six_45_pharm').prop('checked') && !$('#followup_six_45_nurse').prop('checked') && !$('#followup_six_45_none').prop('checked') && !$('#followup_six_45_other').prop('checked')) ||
($('#followup_six_45_other').prop('checked') && $('#followup_six_45_other_text').val() == "" )){
if(( $('#followup_six_45_other').prop('checked') && $('#followup_six_45_other_text').val() == "")){
alert("You selected \"Other\" for race, please fill in what other race you consider yourself to be.");
return false;
}else{
alert("Please select an answer.");
return false;
}
}else{
question_pos+=1;
showContent(question_pos,"right");
progress(93, $('#progressBar'));
return true;
}
this is the problem...
if(( $('#followup_six_45_other').prop('checked') && $('#followup_six_45_other_text').val() == "")){
alert("You selected \"Other\" for race, please fill in what other race you consider yourself to be.");
return false;
Here is html
<div id="area24">
<div id="bl_blue">
<form name="form24" action="handler_2.jsp" onsubmit="return verifyIt();" method="post" style="padding-bottom:20px;">
<input type="hidden" id="from" name="from" value="baseline_01" />
<input type="hidden" id="direction" name="direction" value="" />
<h3>Advice from:</h3>
<table class="screening" width="100%" cellspacing="5px">
<tr>
<td width="8%" align="right"><input name="followup_six_45_physician" id="followup_six_45_physician" type="checkbox" value="1" <%=(session.getAttribute("followup_six_45_physician")!=null && session.getAttribute("followup_six_45_physician").equals("1"))?"checked":""%>/></td>
<td width="92%"><label for="followup_six_45_physician">a physician</label></td>
</tr>
<tr>
<td width="8%" align="right"><input name="followup_six_45_pharm" id="followup_six_45_pharm" type="checkbox" value="1" <%=(session.getAttribute("followup_six_45_pharm")!=null && session.getAttribute("followup_six_45_pharm").equals("1"))?"checked":""%>/></td>
<td width="92%"><label for="followup_six_45_pharm">a pharmicist</label></td>
</tr>
<tr>
<td width="8%" align="right"><input name="followup_six_45_nurse" id="followup_six_45_nurse" type="checkbox" value="1" <%=(session.getAttribute("followup_six_45_nurse")!=null && session.getAttribute("followup_six_45_nurse").equals("1"))?"checked":""%>/></td>
<td width="92%"><label for="followup_six_45_nurse">a nurse</label></td>
</tr>
<tr>
<td width="8%" align="right"><input name="followup_six_45_other" id="followup_six_45_other" type="checkbox" value="1" <%=(session.getAttribute("followup_six_45_other")!=null && session.getAttribute("followup_six_45_other").equals("1"))?"checked":""%>/></td>
<td width="92%"><label for="followup_six_45_other">Other:</label> <input name="followup_six_45_other_text" type="text" value="<%=session.getAttribute("followup_six_45_other_text")==null?"":session.getAttribute("followup_six_45_other_text")%>"/></td>
</tr>
<tr>
<td width="8%" align="right"><input name="followup_six_45_none" id="followup_six_45_none" type="checkbox" value="1" <%=(session.getAttribute("followup_six_45_none")!=null && session.getAttribute("followup_six_45_none").equals("1"))?"checked":""%>/></td>
<td width="92%"><label for="followup_six_45_none">I used none of these</label></td>
</tr>
</table>
</form>
</div></div>
So far, I get an error when the other checkbox is checked, but when I add text to the input, the error still fires. I dont know what to do to make the error only fire when there is no text in the "followup_six_45_other_text" and the "followup_six_45_other" is checked.
Any help would be appreciated, for I am completely stuck right now.