Hello,
Very new to jQuery, but trying to use it to help me with a SharePoint coding solution. I have 6 drop down selection fields that allow the user to select a value between 5 and 100 by 5s. If the sum is over 100 the user should get an alert saying hey you are over 100% allocated
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" >
$(document).ready(function() {
$("input[title='Deal 1 Allocation']").change(function () {
yourCalcFunction();
// whatever else you want to do... (blank out the column value, turn it red, whatever)
});"
$("input[title='Deal 2 Allocation']").change(function () {
yourCalcFunction();
});"
$("input[title='Deal 3 Allocation']").change(function () {
yourCalcFunction();
});"
$("input[title='Deal 4 Allocation']").change(function () {
yourCalcFunction();
});"
$("input[title='Deal 5 Allocation']").change(function () {
yourCalcFunction();
});"
$("input[title='Deal 6 Allocation']").change(function () {
yourCalcFunction();
});"
$("input[title='Other Allocation']").change(function () {
yourCalcFunction();
});"
});
function yourCalcFunction() {
var column1Value = parseFloat($("input[title='Deal 1 Allocation']").val());
var column2Value = parseFloat($("input[title='Deal 2 Allocation']").val());
var column3Value = parseFloat($("input[title='Deal 3 Allocation']").val());
var column4Value = parseFloat($("input[title='Deal 4 Allocation']").val());
var column5Value = parseFloat($("input[title='Deal 5 Allocation']").val());
var column6Value = parseFloat($("input[title='Deal 6 Allocation']").val());
var column7Value = parseFloat($("input[title='Other Allocation']").val());
var totalValue = column1Value + column2Value + column3Value + column4Value + column5Value + column6Value + column7Value;
if(totalValue > 100) alert("Hey Knucklehead you can not be allocated more than 100%");
}
</script>
Sample code for Allocation field
<SharePoint:FormField runat="server" id="ff21{$Pos}" ControlMode="Edit" FieldName="Pct_x0020_Alloc_x0020_1" __designer:bind="{ddwrt:DataBind('u',concat('ff21',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Pct_x0020_Alloc_x0020_1')}"/>