cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript variable to ABAP variable

Former Member
0 Kudos
852

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>)?

View Entire Topic
Former Member
0 Kudos

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

Also,

document.all.customVal

is null.

Former Member
0 Kudos

Hi Kathleen,

Sorry I gave you wrong syntex in my last post.

try this

<b>document.all("put element id here").value</b>

It should give you required value.

Regards,

Narinder Hartala

Former Member
0 Kudos

Narinder,

I am working with Kathleen on this issue.

document.all("customVal") still returns null.

Any other idea?

Joanna Shi

Former Member
0 Kudos

Hi,

If you are using sub-controllers the you have to concatenate controller's ID to your inputField's ID.

e.g. If your subcontroller's id is <b>mySubController</b>

and inputField's ID is 'customVal'

then you can get inputfield's value using code

document.all("mySubController_customVal").value;

Try it once also.

Regards,

Narinder Hartala

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

TIP: You don't have to hardcode the subcontroller ID. In the view coding you can always use controller->component_id to get the current, complete subcontroller ID. That way if your view is reused by one than one controller or a different levels your code doesn't break:

document.all("<%= controller->component_id %>_customVal").value;

Former Member
0 Kudos

Thanks Thomas! It's working. I have a new problem.

After setting the value for the hidden fields, I want to refresh the page and so call a BAPI to update the data in the table. Since this is a view, I will put the BAPI call to the DO_HANDLE_EVENT method. Is this correct? If so, my problem is how can I say that when the refresh is done, it will call the BAPI? I don't have something that would trigger the event.

athavanraja
Active Contributor
0 Kudos
<bsp:htmlbEvent id      = "myid"
                      onClick = "myonclick"
                      name    = "ValueChanged" />
        <script for="IP1" event=onchange type="text/javascript">

      ValueChanged();

      </SCRIPT>

in the above script for="IP1" is the name of the hidden form field.

any value change in that field will trigger serverside event.

Regards

Raja

Former Member
0 Kudos

Hi Raja!

This is my code:

            <htmlb:inputField id = "customVal"
                              type = "string"
                              visible = "false"
                              value="<%=lv_text%>"/>
            <bsp:htmlbEvent id      = "myid"
                          onClick = "update_custom_value"
                          name    = "ValueChanged" />
            <script for="customVal" 
                    event=onchange 
                    type="text/javascript">      
                    ValueChanged();      
            </SCRIPT>   

then a javascript call will place a value on the hidden field, like this:

    
document.all("<%= controller->component_id %>_customVal").value = customValue;

When the value is transferred to the hidden field. I want to call a BAPI. But nothing happens when the hidden field is filled-up with a value. Is there something wrong with my code? Note that this is a view and not a BSP page.

athavanraja
Active Contributor
0 Kudos

may be because its hidden, onchange event is not triggering.

when you set the value using javascript to the hidden field call the valuchanged() function as well.

setvalue();valuechanged();

this will work in view as well.

Regards

Raja

Former Member
0 Kudos

I tried calling the ValueChanged in my javascript code but it shows "page cannot be displayed". What I want is to refresh the page and call the BAPI on refresh. How can I do that?

I added this code in DO_HANDLE_EVENT:


  CASE htmlb_event->server_event.
   WHEN 'update_custom_value'.
         *do call bapi here...
  ENDCASE.

Is this correct?

athavanraja
Active Contributor
0 Kudos

just palce and http break point in your DO_HANDLE_EVENT method (in the starting point) and analyze the event object . as per your requirement the server event is generated with the help of the javascript now, within your method you have to handle.

Regards

Raja

Former Member
0 Kudos

I place a session breakpoint in the DO_HANDLE_EVENT but it doesnt stop there.

How can I do an http breakpoint?

athavanraja
Active Contributor
0 Kudos

to place a http breakpoint, first external debugging should be activated

se80->utilities->settings->abap editor->debugging

check the check box (actv) in external debuggin box

hit enter and come out. now in the do_handle_event method place the cursor where you want to the break point and click the red icon with letters STOP, this will throw a popup asking whether you want HTTP break point or session break point , click the button HTTP break point.

Regards

Raja

Former Member
0 Kudos

I already placed an HTTP breakpoint in the DO_HANDLE_EVENT but it doesnt stop there. It only stops in the DO_INIT and DO_REQUEST. After DO_REQUEST it goes to the page. What do you think is the problem?

Former Member
0 Kudos

Hi,

Just check out whether you have this in your method DO_REQUEST.

dispatch_input( ).

Regards,

Ravikiran.

Former Member
0 Kudos

Yup. dispatch_input( ) is present in DO_REQUEST. But still it doesnt go to DO_HANDLE_EVENT.

athavanraja
Active Contributor
0 Kudos

can you do a search in BSP forum with DO_HANDLE_EVENT. you will find lot of entries, where you could find a solution for your case.

Regards

Raja

Former Member
0 Kudos

Hi Raja!

Its working! I forgot to add an id for the form element that would trigger the event. After that, it worked! It enters the DO_HANDLE_EVENT.

Thanks a lot!

Kathleen

athavanraja
Active Contributor
0 Kudos

Glad to hear that.

Regards

Raja