cancel
Showing results for 
Search instead for 
Did you mean: 

How do I access a request parameter in JavaScript on a report page?

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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> &lt;s c r i p t  src="./dynamicJavaScript.irpt" type="text/ j a v a s c r i p t"&gt;&lt;/ s c r  i p t&gt; </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);

Former Member
0 Kudos

Hmm --

This works for IllumLoginName, but not for a request param that was in the URL, like....?PlantNum=1000

The value of does not get replaced in the script and the actual value of the JS variable is the string .

Thanks for the thought.

Amy Smith

Haworth

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Amy,

this is a test of posting a message to the thread.

Former Member
0 Kudos

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.

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

Nick,

I also tried this one the be able to use the getPropertyValue. The only thing I do not like with this solution is the message "Applet started" in the Status bar of the browser. So the user might ask what this is all about...

Regards

Michael

Former Member
0 Kudos

As long as you have an applet on your page you can use

xx = document.appletname.getPropertyValue(...)

Former Member
0 Kudos

Thanks Nick,

Yes, if I have an Applet.... However, I do not have an Applet on the page.

--Amy Smith

Haworth

jcgood25
Active Contributor
0 Kudos

Looks like SDN needs a reboot, it doesn't want to take my post either...

I sent you an email...

Edited by: Jeremy Good on Feb 21, 2008 11:18 AM

Former Member
0 Kudos

In your body tag you can assign your vars in the onload. For some reason the board wont let me post the code.

Edited by: Christian Libich on Feb 22, 2008 3:27 PM