Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greeting all
How can I write a function that tell me that the object checked satisfied a condition and after that I would have an alert message .
What should I add to this code , knowing that I want to test if my offer checked is internal , I have in my class job offer a bool attribute IsInternal

C#
if ($('.chk-jobOffer:checked').) {

        alert($("#PostErrorMsg").val(), $("#PostMsgTitle").val());

       }


Thanks
Posted

try this..
JavaScript
$("body").on('click', '.chk-jobOffer', function() {
 
 if ($(".chk-jobOffer").is(':checked')) {
                      alert($("#PostErrorMsg").val(), $("#PostMsgTitle").val());
 }
                
  });
 
Share this answer
 
Comments
amiach 16-Apr-14 6:26am    
how can I test that the jobOffer object checked satisfied a condition ?
Murugesan22 16-Apr-14 6:40am    
you want job offer checkbox checked or not,
then you provide checkbox class chk-jobOffer

if you click check box jobOffer

that time you will get result
Brian A Stephens 16-Apr-14 15:33pm    
Your handler will be triggered by ANY element with the class "chk-jobOffer" being clicked. Then your conditional will check if the FIRST such element is checked, which is not necessarily what you want. You are assuming there's only one matching element.
I would populate your IsInternal property as a "data" attribute in each element so you can read it back easily in jQuery:
HTML
<input type="checkbox" name="jobOffers" class="chk-jobOffer" data-is-internal="true" value="1">Offer 1
<input type="checkbox" name="jobOffers" class="chk-jobOffer" data-is-internal="false" value="2">Offer 2
<input type="checkbox" name="jobOffers" class="chk-jobOffer" data-is-internal="false" value="3">Offer 3
<input type="checkbox" name="jobOffers" class="chk-jobOffer" data-is-internal="true"  value="4">Offer 4
</input>

Then, in jQuery, check the data attribute before showing the alert (remember that jQuery transforms the data attributes into camel-case values):
JavaScript
$(document).on('click', '.chk-jobOffer', function() {
  if ($(this).is(':checked') && $(this).data('isInternal') == 'true') {
    alert($('#PostErrorMsg').val(), $('#PostMsgTitle').val());
  }
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900