Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2009 18:58
Show Gist options
  • Select an option

  • Save anonymous/132124 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/132124 to your computer and use it in GitHub Desktop.
<html>
<head><title>:: jQuery ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
</style>
<body>
<form name="listForm" id="listForm">
<input type="checkbox" name="choice" value="2" />2<br/>
<input type="checkbox" name="choice" value="5" />5<br/>
<input type="checkbox" name="choice" value="10" />10<br/>
<input type="checkbox" name="choice" value="20" />20<br/>
Total: <input type="text" size="2" name="total" id="total" value="0"/>
</form>
</body>
<script language="JavaScript" type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script>
<script>
$(function(){
total = document.getElementById('total');
$(document.getElementsByName('choice')).bind('click',function(){
var valTotal = parseInt(total.value),valInput = parseInt(this.value),novoTotal=0;
total.value = (this.checked) ? ( valTotal + valInput ) : ( valTotal - valInput ) ;
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment