Super Web Mart - Discount Coupons & Deals - Discount Promos, Coupon Codes, Discount deals and web site reviews
 

Author Topic: jQuery/javascript Check if Checkbox is Checked  (Read 3022 times)

0 Members and 1 Guest are viewing this topic.

Offline seochapter

  • Administrator
  • Jr. Member
  • *****
  • Posts: 64
    • View Profile
jQuery/javascript Check if Checkbox is Checked
« on: January 25, 2009, 12:00:25 AM »
Hey guys,

I'm looking for a way to check the wrapped set and see if at least one checkbox is checked. I'm working on a site that has a series of checkboxes that allow you to delete the checked rows from the database but before it deletes the records, it pops up with a confirm() javascript box.

My dilemma is that the confirm box pops up even if none of the checkboxes are checked so basically im looking for a way that will display an alert() saying to please check at least one box before pressing the delete selected button but if at least one box is checked then show the confirm box asking are they sure they wanna delete it.

Here is the code for the confirmation but everything i've tried with checking for the checked boxes hasn't worked.

Code: [Select]
$("input.button").click(function(){
     var conf = confirm("Are you sure you want to delete the selected post/s?");
     if (!conf) {
          return false;
     };     
});

Thanks

Webmaster Forum

jQuery/javascript Check if Checkbox is Checked
« on: January 25, 2009, 12:00:25 AM »

Offline rachel

  • Jr. Member
  • **
  • Posts: 23
    • View Profile
Re: jQuery/javascript Check if Checkbox is Checked
« Reply #1 on: December 10, 2009, 10:53:42 PM »
try this script and after that if you have any problem then tell me.
<form name="myform">
<input type="checkbox" name="thatcheckbox" value="checked">Above and Beyond

<input type="checkbox" name="thatcheckbox">Below and Underground

</form>
<script language="Javascript">
if( document.myform.thatcheckbox[0].checked )
alert( "check box 1 is checked" )
</script>

Offline Dordhs

  • Newbie
  • *
  • Posts: 8
  • [url=http://hivescurereview.info]hives cancer[/url] hives heat
    • View Profile
    • hives under breasts  or urtikaria l50
jQuery/javascript Check if Checkbox is Checked
« Reply #2 on: March 28, 2010, 04:05:27 AM »
Why not just check the checkbox status checked/unchecked on submit instead?

Try to add highlighted in your form:
Code:<form name="form1" id="form1" method="test" onsubmit="return updateCheck">...and have this function:
Code:function updateCheckforvar i=0,check=document.getElementByIdform1.getElementsByTagNameinput;i<check.length;ichecki.value=checki.getAttributetype==checkbox&checki.checked?C:N;alertchecki.value; // Verify the values of the checkbox. You can remove thisreturn true;See if it helps.
urticaria allergy  urticaria joe cross

Webmaster Forum

jQuery/javascript Check if Checkbox is Checked
« Reply #2 on: March 28, 2010, 04:05:27 AM »