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
https://forums.phpfreaks.com/topic/204184-tiggering-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.