Solved

Checking value from url with SPFF

Posted on 2010-08-24
6
723 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now