Skip to Content
author's profile photo Former Member
Former Member

Javascript variable to ABAP variable

I have a view that contains the following code:

<script defer language="Javascript" > 
function text_edit(defaultSelected,defaultValue,myForm){ 
if (selectedText == ""){ 
selectedText = defaultSelected; 
selectedValue = defaultValue; 
} 
customTextObject.cSelected = selectedText; 
customTextObject.cValue = selectedValue; 
textEditURL = "TextEdit.htm?option=" + selectedText + "&value=" + selectedValue; 
<b>customValue</b> = window.showModalDialog(textEditURL,customTextObject,customPageFeatures); 
var x = document.getElementById('customVal'); 
x.value = customValue; 
<script> 
..... 
<htmlb:inputField id = "customVal"   
visible = "FALSE"   
value = "<%=<b>lv_customvalue</b>%>"/> 
<htmlb:button text = "Edit"   
onClientClick = "text_edit('<%=lv_selection%>','<%=lv_selectionvalue%>',this.form)"/>

But is says that x is null, meaning document.getElementById('customVal') doesnt get any value. And so, I cannot put the value of the javascript variable to an ABAP variable.

How can I transfer the value of my javascript variable(<b>customValue</b>) to an ABAP variable(<b>lv_customvalue</b>)?

Add a comment
10|10000 characters needed characters exceeded

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 02, 2006 at 01:01 PM

    Is there another way to get the name of the form?

    Also,

    document.all.customVal

    is null.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 02, 2006 at 06:47 AM

    its not possible to assign js variable value to abap var.

    however viceversa is possible.

    you have to go for server round trip.

    do this.

    create an hidden input field assign js var value to it go to server round trip and retreive value.

    check this sample code for this:

    <SCRIPT language="JavaScript">

    function func(){var txt;txt = "Hello";

    document.formBody.if01.value = txt;

    document.formBody.submit();

    }

    </SCRIPT>

    <htmlb:form id="formBody" >

    <htmlb:inputField id = "if01"

    type = "string"

    visible = "false"

    size = "20" />

    here we r assigning value of js var to inputfield and at server event handlling

    get the value and assign it to abap var.

    regards,

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 02, 2006 at 07:29 AM

    Thanks!

    Actually, this view calls a BSP page, I used a javascript to open it in pop-up window (window.showModalDialog). My first option is to put the processing in the view but then based from your reply, I was thinking of processing it in the BSP page(and not in the view which is the calling page). So after submitting the BSP page, I want to call a BAPI, how can I do that? Will I put my call to BAPI in the OnDestroy method?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 02, 2006 at 08:17 AM

    But the problem is my BSP page is a modal pop-up window, when an event is triggered, a new explorer window will be opened. How will I handle this?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 02, 2006 at 09:09 AM

    I have a view that contains the following code:

    <script defer language="Javascript" > 
    function text_edit(defaultSelected,defaultValue,myForm){ 
    if (selectedText == ""){ 
    selectedText = defaultSelected; 
    selectedValue = defaultValue; 
    } 
    customTextObject.cSelected = selectedText; 
    customTextObject.cValue = selectedValue; 
    textEditURL = "TextEdit.htm?option=" + selectedText + "&value=" + selectedValue; 
    customValue = window.showModalDialog(textEditURL,customTextObject,customPageFeatures); 
    var x = document.getElementById('customVal'); 
    x.value = customValue; 
    <script> 
    ..... 
    <htmlb:inputField id = "customVal"   
    visible = "FALSE"   
    value = "<%=lv_customvalue%>"/> 
    <htmlb:button text = "Edit"   
    onClientClick = "text_edit('<%=lv_selection%>','<%=lv_selectionvalue%>',this.form)"/>

    As you can see, the button <b>Edit</b> calls the javascript function <b>text_edit</b>. This function opens a BSP page

    named TextEdit.htm. Here are the contents of TextEdit.htm:

    <script language="javascript">
    function getValue(Cvalue){
        window.returnValue = Cvalue
        window.close();
    }
    </script>
    ...
    <htmlb:form id="customTextForm">
    <htmlb:textEdit id= "customTextArea" rows = "20" cols = "50" text=" "/>
    <htmlb:button id ="create_text" text ="Create Text" width = "50" onClientClick="getValue(customTextForm.customTextArea.value)"/>
    </htmlb:form>

    My problem is how can I put the text entered by user to an ABAP variable.

    My options are:

    a) Process the data(through BAPI call) before the pop-up window is closed.

    or

    b)Since the data is passed back to my view through the javascript variable

    customValue(the one returened by the modal dialog),

    I can do the processing(through BAPI call) in the view, after the pop-up modal window is closed.

    Add a comment
    10|10000 characters needed characters exceeded

    • hi Hemendra,

      I wanted to ask you, on your post you state: "now at server acces the value of inputfield which contains the text entered by user.

      if you do not submit the form then you can access and set your abap variable whenever there is a round trip to server." can you please indicate how this is achieved? Pardon me, I am new to ABAB programming.

      Thanks,

      Chris

  • author's profile photo Former Member
    Former Member
    Posted on Mar 02, 2006 at 10:38 AM

    But the problem is, it doesn't return the name of the form(this.form). That is why my variable myForm is null.

    My view is a fragment only of a whole page. The <htmlb: form> tag is not included in the view. That is why I cannot access the name of the form. And so, I got a null value on line :

    document.myForm.customVal

    .

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.