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 (1)

Accepted Solutions (1)

athavanraja
Active Contributor
0 Kudos

<script language="javascript">

var array=new Array();

array[0]=Value1;

array[1]=Value2;

function mailpage()

{

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

location.href = location_str;

}

</script>

<A href = "javascript:mailpage();">Test</A>

Regards

Raja

eddy_declercq
Active Contributor
0 Kudos

Hi,

First of all, you should avoid giving your array the namy array.

Is SAP_BW_URL an ABAP var or you state this simple as example. Furthermore pls use quotes around you class def for good HTML

Anyway, this should work:

<script language="javascript">

var myArray=new Array();

myArray[0]='Value1';

myArray[1]='Value2';

function goto_URL(url)

{

url = url + myArray[0];

window.location = url;

}

</script>

<a href="javascript:goto_URL(SAP_BW_URL cmd=\'LDOC\'TEMPLATE_ID=\'TEST\'')" class="astyle">test</a>

Eddy

Former Member
0 Kudos

Hi Raja,

Thank you very much for your answer. Is it possible to parameterize the function like following:

function mailpage(value)

{

location_str = "<SAP_BW_URL cmd='LDOC'TEMPLATE_ID='TEST'" + array[value] + ">" ;

location.href = location_str;

}

<A href = "javascript:mailpage(3);">Test</A>

?

athavanraja
Active Contributor
0 Kudos

yes it is verymuch possible and the sample you had shown to pick up the 3 record should work fine.

Regards

Raja

Answers (0)