cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Difference between manual and JavaScript button click

CarstenKasper
Active Contributor
0 Likes
1,412

Hello folks,

I hope this threads fits this forum. It strongly related to the WCUIF but also JavaScript.

The setting:

I got a view that is displayed in a DIV container. This view got a standard <thtmlb:button> which is triggering a round trip when pressed.

When I press the button manually by mouse a correct server roundtrip is done. Delta Handling takes care that only this one view is refreshed. Everything is wonderful.

Now the issue:

I need to "press" this button using JavaScript. It is no problem to get a handle to the correct button and JavaScript provides two methods focus() and click() to call both JavaScript functions that are triggered when the button is pressed manually.

The coding looks like this


var button = getElementById('Id of my button');
button.focus();
button.click();

Now a server roundtrip i done, but it seems to be a roundtrip for the whole WebClient. Even worse: The UI freezes with the spinning "Please Wait..." showing.

Does anybody know how to do a correct, delta handled round trip that is invoked not by the user but JavaScript?

I already tried putting and calling the bsp:htmlbEvent. It behalves like the button described above.

Thankful for any pointers!

cheers Carsten

View Entire Topic
Former Member
0 Likes

Hi Carsten,

I tried it but button.click() triggers onClientClick and not a server event. Try the below solution,

1. Assign a bsp:htmlbEvent.

<bsp:htmlbEvent name = "fireMyEvent"

id = "fireMyEvent"

p1 = "p1"

p2 = "p2" />

2. Assign a javascript function to button onClientClick event and trigger it through javascript.

<thtmlb:button id = "mybutton"

text = "Submit"

onClientClick = "upload_file( );" />

<scrpt language="javascrpt">

var button = document.getElementById("<%= controller->component_id %>_mybutton");

button.focus();

button.click();

</scrpt>

3. Inside the function you can trigger server event using fireMyEvent(...)

<scrpt language="javascrpt">

function upload_file( )

{

....

....

return fireMyEvent('Submit');

}

</scrpt>

4. In event handler method EH_ONSERVEREVENT, proceed by checking htmlbEvent parameters,

lr_event ?= htmlb_event_ex.

IF lr_event->p1 EQ 'Submit'.

...

Endif.

Regards,

Arun

CarstenKasper
Active Contributor
0 Likes

Hi Arun,

thanks for your response.

As mentioned by me before:

I already tried putting and calling the bsp:htmlbEvent. It behalves like the button described above.

This sentence means I already tried what you described below.

I tried it but button.click() triggers onClientClick and not a server event.

For me infact the javascript button.click() triggers the javascript function that the framework has rendered into the HTML result that is send to the browser. On this level there is no such thing as onClientClick. The onClientClick is solely on HTMLB level, but not in the HTML send to the browser.

When you inspect the HTML code for the <a> anchor tag that is rendered you will the that there are two event handlers defined:

onfocus and onclick.

The onClick calls a JavaScript function that triggers the roundtrip after some other checks. The code looks something like this:


htmlbSL(Handle to my button,2,'my button ID:serverEvent','0');

I debugged the whole process that is started when I click on the button manually as well as the process that is started when I call button.click() in my JavaScript code. They seem to be identical.

I assume that there is some other event handler registered for the CLICK, MOUSEDOWN, MOUSEUP, form submit or similar event that I do not catch while debugging.

To mention some functions I run across:

htmlbSL()

htmlbSubmitLib()

htmlbSubmit()

htmlbSubmitForm()

Note: There exist two htlmbSubmitForm() functions one in events.js and one in scripts.js. The one in scripts.js is called.

cheers Carsten