|
|
|
|
|
|
|
|
|
|
|
|
|
|
Using JavaScript to get the Query_String from a frameset (continued)
Here is how you can get a parameter using the above function:
var productNameLink = getParameter ( framesetQuery, 'productname' );
|
In my application, I put the code above in the JS Header. Later on, when I am actually assigning the value to a field, I reference this parameter in the onLoad event.
One key thing to remember here is that JavaScript is case-sensitive. Therefore, whenever I'm working with things like parameter names or frame names, I usually always try to make them all lower case in order to eliminate case-related problems.
Manipulating the result Once you've gotten the value of a parameter from the Query_String you might need to manipulate it. For instance, in order to pass values containing spaces, you have to put plus signs where the spaces were so they will work in the URL. On my form, I've got two variables. The first is productNameLink. It is exactly equal to the parameter value, including plus signs. The second variable is called productName, and it's computed using the "replaceSubstring" JavaScript function below (which you should place in the JS Header section of your form) to replace the plus signs with spaces once again. As you'll see in the final section, when I'm writing code back to the browser, I'll need to use both of these variables.
function replaceSubstring ( inputString, badString, goodString, caseSensitive ) {
fixedReplace = " ";
UI = inputString;
UB = badString;
if ((caseSensitive !=1) && (caseSensitive != true)) {
UI = inputString.toUpperCase();
UB = badString.toUpperCase();
}
badEnd = -1;
badLoc = UI.indexOf(UB);
if (badLoc != -1) {
for (x=1; (badLoc != -1); x++) {
fixedReplace = fixedReplace + inputString.substring((badEnd + 1), badLoc) + goodString
badEnd = badLoc + UB.length - 1;
badLoc = UI.indexOf(UB, (badLoc + 1)); }
fixedReplace = fixedReplace + inputString.substring((badEnd + 1), inputString.length); }
else { fixedReplace = inputString; }
return fixedReplace;
}
|
You can then manipulate the value of the parameter in the JS Header with the following code:
var productName = replaceSubstring ( productNameLink, "+", " ", false);
|
Notice how I used the productNameLink variable I had already computed above and simply replaced the plus signs with spaces.
But wait, there's more! As a special bonus, I'm also going to include a JavaScript "trim" function that will help you to remove any extraneous leading or following spaces that you might have in a string:
function trim ( inputStringTrim ) {
fixedTrim = "";
lastCh = " ";
for (x=0; x < inputStringTrim.length; x++) {
ch = inputStringTrim.charAt(x);
if ((ch != " ") || (lastCh != " ")) { fixedTrim += ch; }
lastCh = ch;
}
if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); }
return fixedTrim
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Sophisticated Meets Simple For Document Management
Share. Control. Manage.
Documents, emails, and content in the context of how work is done.
Native to Lotus Domino. The User Experience unseen for Lotus Domino.
Do more with less. Really.
See the possibilities Docova unleashes for Lotus Domino. |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|