|
|
|
|
|
|
|
|
|
|
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
}
|
[ Prev | Next ]
|
|
|
|
|
|
-- Advertisement --
Learn Notes and Domino 8 at your place and pace!
Learn Notes and Domino in your office and/or home! TLCC's highly acclaimed distance learning courses for users, developers, and admins will enhance your career and your resume.
The many included activities and demos will make you a pro! Expert instructor help is a click away.
Click here to try a FREE demo course!! |
-- Advertisement --
DEPARTMENT CALENDAR - MANAGE AND SHARE A COMMON CALENDAR WITH YOUR TEAMS
Are you responsible for improving your organization's Group Calendaring tool? Have you been tasked to find a true group calendar tool with Itinerary, Time-Off, Sign In/Out and Bulletins/Events module that seamlessly integrates with Domino calendaring?
If so, Logic Springs Technologies will make answering these questions a whole lot easier!
Learn how by visiting us at www.departmentcalendar.com |
|
|
|
|
|
|
|
|