on 2005 Apr 27 8:58 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.