on 02-21-2008 2:23 PM
Hi all,
In an irpt page I want to access the value of the request parameter in javascript so I can set the selected option in a <select>. The select tag is generated with <SERVLET> and StyleSheet param. I want to do something similar to JSP coding that puts the param value into a JavaScript variable.
var myVal = '<%= request.getParameter(...) %>';
I can put the value of the parameter in the page header using . However I can't seem to be able to set a javascript variable. I finally did the following:
<span id="thePlantNum" style="visibility: hidden">{MyParam}</span>
<xxxscript language="JavaScript">
var theSpan = document.getElementById('thePlantNum');
plantNum = theSpan.innerText; // I know -- IE only
selectPlant(plantNum); // The function that selects the correct option
</xxxscript>
It seems not so elegant. Is there a better way?
Thanks,
Amy Smith
Haworth
A solution can be to include a Javascript file with an ending .irp onstead of .js in our filename.
So create a standard irpt page where you include via this html tag an external Javascript file
<b> <s c r i p t src="./dynamicJavaScript.irpt" type="text/ j a v a s c r i p t"></ s c r i p t> </b>
<i>Sorry it looks that the forum does not allow some special reserved words to include here so I insert spaces. But I think you understand that and know how to write it correct in your webpage.</i>
Now create a javascript file called as dynamicJavaScript.irpt and insert something like this:
myVar = "{IllumLoginName}";
aler t("My loginname = "+myVar);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tested putting the javascript variable assignment in the body tag's onload event:
..."aVar='';" ...
This works and assigns the value of the URL param PlantNum to the javascript variable aVar that was declared above. Much more elegant than my span tag.
Thanks to Christian and Jeremy!
--Amy Smith
Haworth
Hi Amy,
First of all the replacement of so called Session-Variables only works on "*.irpt" pages. But I'm sure you have known this before. And besides this the replacement will only work in the body of your HTML page and not between the script-Tags.
Also the Session-Variable either is part of the URL like &thePlantNum=4711 or it is set before by using document.AppletName.setPropertyValue("thePlantNum","4711").
As the replacement is only done in the body of your HTML Page you can use a hidden input-Field (it's the same like you did just smarter in my oppinion):
input id="id_thePlantNum" type="hidden" value=""
And then pick it up in Java_Script with document.getElementById("id_thePlantNum").value
This also works with Custom Attributes which are a special kind of Session-Variabels and Localisation-Values, e.g. if you like to post an error message in different languages:
input id="msg_error" type="hidden" value="{##Projectname_msg_error}"
As this question was already answerd take this as a summary. Comments still welcome.
Ciao
Martin
PS: If you have an Applet on the target page you can also use document.AppletName.getPropertyValue("thePlantNum"); in Java_Script. But this works only if you have an applet as you said :-).
To modify this page that it was accepted tooks me longer than to write what I'd like to say.
I tried adding an empty applet, as below, and it worked fine with getPropertyValue. This could be useful too, especially if you are wanting to access lots of different parameters.
<applet height=1 width=1 name=appSave CODE="iCommand" CODEBASE="/XMII/Classes/" ARCHIVE="illum8.zip" MAYSCRIPT>
</applet>
Edited by: Nick Stannage on Feb 26, 2008 10:44 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As long as you have an applet on your page you can use
xx = document.appletname.getPropertyValue(...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
7 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.