troubleshooting Question

SharePoint Custom Script jQuery

Avatar of Matt Pinkston
Matt Pinkston asked on
JavaScriptJScript
12 Comments1 Solution501 ViewsLast Modified:
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')}"/>
                                          
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros