Jump to content

tiggering function


Destramic

Recommended Posts

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.