Solved

Checking value from url with SPFF

Posted on 2010-08-24
6
766 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

738 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