Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  161] [ 1]  / answers: 1 / hits: 17744  / 13 Years ago, wed, november 30, 2011, 12:00:00

I have a function for a button which submits a form. This function checks to see if the 5 checkboxes are selected #co1,#co2,#co3,#div1,#cc1.



It then also checks to see if tcaccept select is set to 1.
If so the form submits, else the alert pops up.



This is the code i have at the moment:



  $('#submit2pd').click(function(event) {
var $finishBoxes = $('#co1,#co2,#co3,#div1,#cc1');

if (!($finishBoxes.length == $finishBoxes.filter(':checked').length && $('#tcaccept').val() == '1' )) {
alert('Please complete the Induction Checklist confirming that you have read and understood the Colleges main policies and procedures, agreeing to comply with these in line with the terms of your contract with the College');
return false;
}

// otherwise the form is submitted
window.location.href = submit2pd.php;

});


All works brilliantly, but i want to add to this line as i have another option that is required. But this needs to be an if statement.



    if (!($finishBoxes.length == $finishBoxes.filter(':checked').length && $('#tcaccept').val() == '1' && THE IF STATEMENT))


this is what i need to incorporate into the if statement above.



if ($(#ctl).val() == 1) {
$('#ctlapp') must not be blank
}
else if ($(#ctl).val() == 0) {
$('#ctlapp') can be blank
}


Any help would be greatly appreciated.


More From » jquery

 Answers
1

How about:



if (!($finishBoxes.length == $finishBoxes.filter(':checked').length && 
$('#tcaccept').val() == '1' &&
!($(#ctl).val() == 1 && $('#ctlapp').val() === )))


What we're adding here is another condition which says, And make sure it's not the case that #ctl is 1, and #ctlapp is blank.



Edit: and please see my comment above - your question is not about jQuery, forms, or validation. It's barely about JS.


[#88826] Tuesday, November 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rayvencallij

Total Points: 93
Total Questions: 80
Total Answers: 85

Location: Argentina
Member since Thu, Mar 18, 2021
3 Years ago
;