cancel
Showing results for 
Search instead for 
Did you mean: 

JS and cookies

Former Member
0 Kudos
110

Hello,

I am new at JS and have some problems in evaluating a value returned from a function.

This is the case :

I call a JS-function which gives me a value back, in my case a language-key which is stored in cfoo.

In my page I want to evaluate this value and set a corresponding ABAP-variable like this :

var cfoo=csearch("c_spras");

document.write(cfoo); // N, F, E or D

switch (cfoo){

case "N":

<% spras = 'N'. %>

break;

case "F":

<% spras = 'F'. %>

break;

case "E":

<% spras = 'E'. %>

case "D":

<% spras = 'D'. %>

default:

<% spras = 'E'. %>

break;

}

</script>

The variable cfoo is filled with the correct value, i.e. N, F, E or D but the switch statement always returns the default value.

Can someone tell me what I am doing wrong ?

Thanks in advance,

Dirk.

Accepted Solutions (1)

Accepted Solutions (1)

Ulli_Hoffmann
Contributor
0 Kudos

Hi,

you're mixing up processing of ABAP coding on the server and javascript code in the client.

Do a 'view Source' in the browser and you will see that the ABAP statements in <% .. %> are not there.

So you're coding won't work. 'spras' contains always 'E' because this is the last value

it gets assigend on the server.

Now try the following:

a) define a inputfield in your bsp page like:

<htmlb:inputField id = "if01"

value = "test"/>

b) remove the switch statemnet, add document.getElementById("if01").value = cfoo;

The inputfield should display the value of cfoo.

regards, Ulli

Answers (1)

Answers (1)

maximilian_schaufler
Active Contributor
0 Kudos

Be careful here ...

You are running a javascript function, which has some ABAP code in it ... ABAP is run server side, whereas I guess your javascript is within the layout code and therefore run client side.

Check your HTML source code within the browser, you will not see any ABAP code there, and so you will see that this cannot work.

To set an ABAP variable you have to somehow submit the information to the server.

Max

P.S.: Got beaten ...

Should not have gone for a drink while writing my answer

Message was edited by: Maximilian Moder

Former Member
0 Kudos

Thanks Ulli and Max,

You've cleared some things out for me.

Dirk.