Destramic Posted June 8, 2010 Share Posted June 8, 2010 hey guys working on a select/deselect all script and im having a few teething problem...bassically when you load the page the script works fine...but when i checkbox is checked/uncheck the function needs to be ran to return new output...but im having a probelm doing this...help please? <!DOCTYPE html> <html> <head> <script type="text/javascript" src="/ajax/jquery/libary/jquery.js"></script> <script> $(document).ready(function(){ function toggleCheckboxes(group, element, status){ group = $('input[name='+ group +']'); element = $('#'+ element +''); status = $('#'+ status +''); var group_checkbox_count = $(group).length; var group_checked_count = $(''+ group + ':checked').length; var selected = ('(' + group_checked_count + ' out of ' + group_checkbox_count + ' selected)'); $(status).text(selected); if ($(element).text() == '') { if (group_checked_count/group_checkbox_count < 1) { $(element).text('Select All'); } else{ $(element).text('Deselect All'); } } } $(":checkbox").click(toggleCheckboxes()); toggleCheckboxes('sports', 'selectbutton', 'selected'); }); </script> </head> <body> <form> <span id="selectbutton"></span><br/> <span id="selected"></span><br/><br/> Soccer: <input type="checkbox" name="sports" value="soccer" /><br /> Football: <input type="checkbox" name="sports" value="football" checked /><br /> Baseball: <input type="checkbox" name="sports" value="baseball" /><br /> Basketball: <input type="checkbox" name="sports" value="basketball" /> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.