Skip to Content
avatar image
Former Member

Simulation of button push via JavaScript in HTMLB pages

Can anyone shed some light on simulatinh button clicks via JavaScript in HTMLB pages?

In "old-style" HTML BSP pages, you could execute the following:

document.form[0].elements["onInputProcessing(find)"].click()

to simulate clicking a "find" button; the oninputprocessing event handler would then execute. In HTMLB pages, the above JavaScript generates an error, as the object does not exist. Looking at the rendered page code, the HTMLB button with the "id = find" tag data is rendered as a JavaScript event.

As a quick & dirty shortcut, I defined an "type=submit" button and hid it with a <div> tag. Now I can access the hidden button via JavaScript as before, and the oninputprocessing BSP event handler fires, but the event ID for the hidden button is not set.

Can anyone tell me what I'm missing here?

Many thanks,

D.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Jun 10, 2004 at 04:42 PM

    Hallo Dorian,

    What was that old saying about "one picture is worth a thousand words"? Let us see:

    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <htmlb:content design="design2003">
     <htmlb:page>
      <htmlb:form>
       <htmlb:button id            = "btn1"    
                     text          = "Press Me"
                     onClientClick = "alert('off we go!');"
                     onClick       = "myClickHandler" />
       <script>
           document.all.btn1.click();
       </script>
      </htmlb:form>
     </htmlb:page>
    </htmlb:content>

    Does this do what you want? Be careful, I am no JavaScript expert, and suspect that the above might not work in Netscape. You will have to test.

    Also the ".click()" sequence is very much dependant on the HTML that is rendered for the button. Should this ever change in feature, of course you might have to recode that part.

    Why the hidden <div> with <input type=submit> does not work as expected? The reason is that all events of the HTMLB libraries are put into one central JavaScript function HtmlbSubmitLib. This function sets a number of hidden input fields that are required for the event handling, before the form is submitted.

    You could of course consider to trigger this function yourself. This function HtmlbSubmitLib's interface will not change anymore. However, the only way that we support on the server to build strings to call this, is if you have already an BSP-element available. So maybe this trick with the button above is easier.

    b.

    Add comment
    10|10000 characters needed characters exceeded