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


LVL 5
ydsonlineAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT 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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.