Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 782
  • Last Modified:

Checking value from url with SPFF

I need some help from someone that is well familiar with SPFF and Javascript.

One of the functions of SPFF is that you can lock a field and change the bacground color of the locked field.
The function to change the background color is:
$.spff({lockColor:"green"});

Open in new window


This works well but I need the ability to change the color based on a value that has been passed on from the url to a field in the NewForm.aspx page.

For example:
if the url is: http://sharepointsite/Lists/TestList/NewForm.aspx?Status=Yes
I need the background color to be "Green" when the value of Status is "Yes" and "Red" when the value of Status is "No"

I have a basic idea of how to do this but don't know what code to use to check whether the value of Status is Yes or No. I've gone through the spff.js and jquery.js but don't know enough of Javascript to be able to figure out the code to check on the values in the url or field.

Code in the NewForm.aspx page should be something like:

<SCRIPT type=text/javascript>

$(function(){

 if(Status=="Yes") {  //example of what I would like to achieve
      $.spff({lockColor:"green"});
}
else {
 if(Status=="No") {  //example of what I would like to achieve
     $.spff({lockColor:"red"});
  }
}
});
   
</SCRIPT>

Open in new window


So in summary, I need some help with the code on how to properly check whether the Status value is "Yes" or "No" either by checking the field directly or checking the values that are in the url itself.

So just to clarify the piece of code I need help with is:
 if(Status=="Yes") {

Open in new window

unless there is another way of doing this.

Your help will be much appreciated!
Thanks
YDS


0
ydsonline
Asked:
ydsonline
  • 5
1 Solution
 
Michel PlungjanIT ExpertCommented:
Like this?

function parseQString(loc) {
  var qs = new Array();
  loc = (loc == null) ? location.search.substring(1):loc.split('?')[1];
  if (loc) {
    var parms = loc.split('&');
    for (var i=0;i<parms.length;i++) {
      nameValue = parms[i].split('=');
      qs[nameValue[0]]=(nameValue.length == 2)? decodeURIComponent(nameValue[1].replace(/\+/g,' ')):null; // use null or ""
    }
  }
  return qs;
}
function getQSParm(parm) {
  return (qs[parm])?qs[parm]:null
}

var qs = parseQString(); // 
window.onload=function() {
  var color= getQs("Status")=="Yes"?"green":"red"
  $.spff({lockColor:color});
}

Open in new window

0
 
ydsonlineAuthor Commented:
Thanks for your reply mplungjan. I just tried that but it doesn't seem to work.

i get an "object expected" at this line:

var color= getQs("Status")=="Yes"?"green":"red"

Open in new window

0
 
ydsonlineAuthor Commented:
i got rid of the error by doing the following change to the code, but now it's now showing the values at all in the field nor the background color. Any ideas?
 


$(function parseQString(loc) {  
  var qs = new Array();  
  loc = (loc == null) ? location.search.substring(1):loc.split('?')[1];  
  if (loc) {  
    var parms = loc.split('&');  
    for (var i=0;i<parms.length;i++) {  
      nameValue = parms[i].split('=');  
      qs[nameValue[0]]=(nameValue.length == 2)? decodeURIComponent(nameValue[1].replace(/\+/g,' ')):null; // use null or ""  
    }  
  }  
  return qs;  
}  
function getQSParm(parm) {  
  return (qs[parm])?qs[parm]:null  
}  
  
var qs = parseQString(); //   
window.onload=function() {  
  var color=getQs("Status")=="Yes"?"green":"red"  
  $.spff({lockColor:color});  
} 

}); 

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
ydsonlineAuthor Commented:
something I haven't mentioned, and I don't know if this would make a difference is that my actual field name has two words e.g. "Status onhold" and not just one word as in the example "Status", so it has a space in between.
0
 
ydsonlineAuthor Commented:
I finally got it to work with your code. I think you might have had a typo. I changed getQs to getQSParm and that resolve it. It works great now thanks.
 

 var color=getQSParm("Status")=="Yes"?"green":"red"

Open in new window

0
 
ydsonlineAuthor Commented:
Thanks for your help.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now