2

so i want to disable the input button function unless checkbox is checked. I want not a specific one checkbox but IF a checkbox or multiple checkboxes are checked the button, which is a delete button, will be enabled. the issue im having is that the delete button is only enabled when the first checkbox is checked. say for example the second or third checkbox were checked the delete button is still disabled unless the first checkbox is checked as well.

is there a way around this?

the button :

  <input type="submit" id="del_event" name="del_event" value="Delete Event"/>

the checkbox is echoed this is the coding:

  echo 
   "<tr>
    <td><input type='checkbox' name='check' id='check'/><a href='' class='event-link'>$name</a>  
    </td><td>$date</td><td>$time</td><td>$venue</td>
  </tr>";

the script im using is:

   var chkbox = $("#check"),
            button = $("#del_event");
       button.attr("disabled","disabled");
        chkbox.change(function(){
            if(this.checked){
                button.removeAttr("disabled");
            }else{
                button.attr("disabled","disabled");
            }
        });

any help is appreciated.

1
  • #check as an identifier is your main problem - an id is supposed to be completely unique: on only 1 element in a page. Commented Apr 18, 2014 at 8:54

1 Answer 1

3

Change your checkbox generated code like this:

 echo 
   "<tr>
    <td><input type='checkbox' name='check' class='check'/><a href='' class='event-link'>$name</a>  
    </td><td>$date</td><td>$time</td><td>$venue</td>
  </tr>";

Since you are wanting to fire this event for every check boxes you need to use class instead of id in the checkbox. in jquery:

       var chkbox = $(".check");
       button = $("#del_event");
       button.attr("disabled","disabled");
       chkbox.change(function(){
            if(this.checked){
                button.removeAttr("disabled");
            }else{
                button.attr("disabled","disabled");
            }
        });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.