Solved

Checking value from url with SPFF

Posted on 2010-08-24
6
752 Views
Last Modified: 2012-05-10
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
Comment
Question by:ydsonline
  • 5
6 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 33518948
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
 
LVL 5

Author Comment

by:ydsonline
ID: 33519055
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
 
LVL 5

Author Comment

by:ydsonline
ID: 33519112
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 5

Author Comment

by:ydsonline
ID: 33519145
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
 
LVL 5

Author Comment

by:ydsonline
ID: 33643513
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
 
LVL 5

Author Closing Comment

by:ydsonline
ID: 33643517
Thanks for your help.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question