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,407

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

Accepted Solutions (0)

Answers (2)

Answers (2)

CarstenKasper
Active Contributor
0 Likes

Another day of debugging solved the problem.

When using the thtmlbAjaxRequest do not start another request while you are still in the result handler of the first. Put the button.click() in another function and everything works as expected.

cheers Carsten!

Edited by: Carsten Kasper on Sep 29, 2010 5:19 PM

Former Member
0 Likes

Hi Carsten,

I am also trying the same thing but not been able to trigger the event programatically. below is my code:

<bsp:htmlbEvent name = "fireEvent"
                 id   = "fireEvent"
                 p1   = "p1"
                 p2   = "p2" />

<thtmlb:button id            = "mybutton"
     text          = "Submit"
     onClientClick = "sessionexit( );" />

<script language="javascript" type="text/javascript">
        function sessionexit( )
      {

          var button = document.getElementById("<%= controller->component_id %>_mybutton");
          button.focus();
          button.click();
          return fireEvent('Submit');
      }
</script>

Could you please give me some heads up on this? Thanks for your help.

Regards,

Ashish

CarstenKasper
Active Contributor
0 Likes

Hi Ashish,

if I remember correctly, it is almost 2 years by now, for me the problem was that I tried to trigger the server roundtrip in a handler method automatically called by the THTMLB Ajax library. This does not work. Do not know why exacatly, it just doesn't.

Solution in my case:

Set a helper variable in the ajax handler and call an additional method with window.setTimeout() to trigger the roundtrip.

As I switched customers a while ago, I do not have access to the system where this issue was solved to recheck.

cheers Carsten

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