cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Java Script variables to ABAP

Former Member
0 Kudos

We are working on a BSP application and ran in to an issue. Does anyone know how to pass a value of a variable in Java(HTML) to ABAP?

HTMLB does not support drop down boxes within a Tree Node, therefore we were forced to use standard HTML with the HTMLB Tree Node function as below:

<% wf_string1 = ' TR - CM Trans Cash Mgmt&nbsp <select id= "select1" name="select1">'.

loop at tab into wa_value.

clear wf_option.

concatenate: '<option value="' wa_value '">' wa_value '</option>' into wf_option.

concatenate wf_string2 wf_option into wf_string2.

endloop.

concatenate wf_string1 wf_string2 '</select>' into wf_text. %>

<htmlb:treeNode id = "Test"

text = "<%= wf_text %>"/>

</htmlb:treeNode>

</htmlb:tree>

<br>

We are then trying to get the value from the html <select> <option> in to ABAP and this is where we are having a problem figuring it out.

Any Help would be greatly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

athavanraja
Active Contributor
0 Kudos

Welcome to SDN.

onchange of the dropdown set the selected value to a hidden form field and you have to make a server roundtrip to be able to assign ito to ABAP variable.

Regards

Raja

maximilian_schaufler
Active Contributor
0 Kudos

Hi Eric,

it seems you haven't worked with JavaScript a lot before.

You cannot pass a javascript variable to ABAP in an instant - this is because javascript runs on the client and ABAP on the server.

The way to connect client and server is HTTP, therfore you have to use HTML form elements that get submitted in the HTTP request for your javascript variable.

Just like Raja mentioned for example.

In addition may I recommend www.w3schools.com as an excellent resource for HTML, JavaScript and lots of other useful stuff when starting with web development.

Cheers,

Max

Former Member
0 Kudos

Thanks Raja,

I am new to the Java Script and was wondering if you could provide a quick example of what you mean or a link with an example. This is kind of confusing!

Thanks for your help!

Eric

Former Member
0 Kudos

Hai check out this code


<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
  <htmlb:page title="Input prompt " >
  <script language="JavaScript" type="text/javascript">
                 function save_input_prompt()
                 {
                  var varient_name = prompt("Save Varient as ?","");
                   if (varient_name == null )
                   return false;
                   else if (varient_name == "" || varient_name == " ")
                    {
                      alert("Enter a valid input");
             	        return false;
                    }
                   document.mainform.if_varient_name.value =varient_name;
                   alert( document.mainform.if_varient_name.value );
                  return true;

                 }
      </script>
    <htmlb:form id="mainform" >

      <htmlb:inputField id    = "if_varient_name"
                        value = "abc"
                        visible = "false" />
      <htmlb:button id            = "save_query_open"
                    text          = "Save as"
                    onClick       = "EVT_SAVE_QUERY"
                    onClientClick = "if(!save_input_prompt()) htmlbevent.cancelSubmit=true;"
                    tooltip       = "Save Query" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

oninputprocessing


DATA lv_string TYPE string.
lv_string = request->get_form_field( 'if_varient_name' ).

Regards,

Venkatesh

Former Member
0 Kudos

Venkatesh

That is GREAT! Thanks for the help!

Eric

Former Member
0 Kudos

Hai Eric,

If your problem is solved Dont forget to mark is solved and reward points,

Regards,

Venkatesh

Answers (0)