cancel
Showing results for 
Search instead for 
Did you mean: 

adding Javascript variable to <a href=....

Former Member
0 Kudos

Hello @ all,

I want to use a value of a Javascript array in a HTML like

<script>

var array=new Array();

<b>array[0]</b>=Value1;

array[1]=Value2;

</script>

<a class=SAPBEXBtnStd href="<SAP_BW_URL cmd='LDOC'TEMPLATE_ID='TEST'+<b>array[0]</b>>">to TEST</a>

How can I do this?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I would suggest an alternative solution. I notice you are using Web Commands. Instead of using the Web Commands in tags (<SAP_BW_URL cmd='LDOC' TEMPLATE_ID='TEST'>), I would suggest you write the javascript yourself.

Example:

<script>

var myArray = new Array();

myArray[0] = "hello";

myArray[1] = "world";

myHTMLpath = SAP_BW_URL_Get() + "&CMD=LDOC" + "TEMPLATE_ID=" + myarray[0] + myArray[1];

//output the link to the screen

document.write('<a class=SAPBEXBtnStd href=' + myHTMLpath + '>Click Here to Test</a>');

</script>

Former Member
0 Kudos

Hi Mehmet,

as far as I understand your problem, you're mixing up server side und client side dynamics and scripting.

First of all the statement

href="<SAP_BW_URL cmd='LDOC'TEMPLATE_ID='TEST'+array[0]>"

is parsed and replaced on the server and generates some html-code-fragement like this

href="http://server/bw-url/ldoc-cmd?template_id='TEST+array[0]'

At this moment the array is part of a string and not a javascript-variable. No way to get this into the correct form.

The only way imho to avoid this problem is:

1. Let the server store the url to your bw-server in a javascript-var

var serverLink=SAP_BW_URL cmd='LDOC'TEMPLATE_ID='TEST'>

-> problem is: the template 'Test' musn't exist!?!

2. Append the array value to the generated url on click:

<script>....
function navi(pos) {
  document.location.href = serverLink+array[pos];
}
</script>
<a href="javascript:navi(0)">to Test</a>

Something like this could work..

Hope that helps, Thomas

Former Member
0 Kudos

you can't pass variable directly (except document.write)

I think the best way to solve problem is making javascript function

eq.


<script>
var array=new Array();
array[0]="Value1";
array[1]="Value2";

function openWin(a)
{
	window.open("<SAP_BW_URL cmd='LDOC'TEMPLATE_ID='TEST'"+array[a], "_self")
}
</script>

<a href="javascript:openWin(0)">to TEST</a>

in openWin(), in a href, put variable you want