cancel
Showing results for 
Search instead for 
Did you mean: 

Fire onClick-Event for a button to call a JavaScript function

Former Member
0 Kudos

Hi experts,

I have to open a window to show the value help for a field in a tableview (htmlb). After clicking a table row, the value is to be transferred into the calling page, the window is to be closed automatically. It's OK when using radio buttons instead of a tableview or with an additional button ( <input type="button" id="JAVA" value="SUBMIT" onclick="set_value('<%= gv_bname %>')"> ) to trigger the client event. But how can I fire the client event (onClick) without pushing the button (JavaScript?)

The calling BSP:

<htmlb:inputField id = "f4_user"

value = "<%= gv_bname %>"

showHelp = "TRUE"

onValueHelp = "ShowModalBox_f4user(document.main.f4.value)" />

The called BSP "F4":

Layout:

<% concatenate 'F1 = window.opener.document.forms.main.elements.f4.value =value;' into lv_string . %>

<htmlb:form...

<SCRIPT language="JavaScript">

function set_value(value)

{ <%= lv_string %> self.close(); }

</SCRIPT>

...

<htmlb:tableView id="users"

table="<%= gt_users %>"

onRowSelection="RowSelect"

selectionMode="SINGLESELECT" >

"f4", OnInputProcessing:

when 'RowSelect'.

lref_tableview ?= cl_htmlb_manager=>get_data(

request = request

name = 'tableView'

id = 'users' ).

if not lref_tableview is initial.

clear lv_ind.

lv_ind = lref_tableview->data.

clear pas_user_addr.

read table pat_user_addr into pas_user_addr

index lv_ind->row_index.

if sy-subrc = 0.

gv_bname = pas_user_addr-bname.

endif.

I've searched through the forum, but couldn't find the solution for my problem.

I'd appreciate your help!

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

Look at the below thread to trigger event without pushing the button:

<i>* Reward each useful answer</i>

Raja T

Former Member
0 Kudos

Hi Raja,

thanks a lot! I saw this thred before, but javascript was not called. Now I know, HTMLB objects (tableview or button) trigger server events, but I needed a client event for javascript. With the following coding it works!

<% if gv_bname is not initial. %>

<input type="button"

id="JAVA"

value="SUBMIT" onclick="set_value('<%= gv_bname %>')">

<script>

document.getElementById('JAVA').click();

</script>

<% endif. %>

But still I wonder, whether it's possible to call javascript directly after selecting a row in the tableview. The problem is, that a server event is triggered (onInputProcessing), and I didn't manage to call Javascript from Layout.

Do you have an idea?

best regards

raja_thangamani
Active Contributor
0 Kudos

In a simply way, as you said when you click tableview it triggers the server event. At that point set some flag say row_selected.

In layout, execute your javascript if row_selected is set.

Sample code..

<% if row_selected is not initial.. %>

open window....

<% endif. %>

Raja T

Former Member
0 Kudos

That was my first idea, too. But Javascript was not processed after OnInputProcessing. The window was empty, but was not closed and the value was not transferred into the field on the main screen.

<% if gv_bname is not initial. %>

<SCRIPT language="JavaScript">

function set_value(value)

{ F1 = window.opener.document.forms.main.elements.f4_user.value =value;

self.close(); }

</SCRIPT>

<% endif. %>

Later I had the idea to fire a client event via a push button (HTML, No HTMLB).

I've no experience with Javascript, but I see in Debugger, that ABAP-Coding is processed, but Javascript not...

Thanks

raja_thangamani
Active Contributor
0 Kudos

You cant debug the javascript...but u can troubleshoot using alert('your message'); it will show the pop up..so that you will come to know whether JS code is executed or not..

<i>* Reward each useful answer</i>

Raja T

athavanraja
Active Contributor
0 Kudos

<i><% if gv_bname is not initial. %>

<input type="button"

id="JAVA"

value="SUBMIT" onclick="set_value('<%= gv_bname %>')">

<script>

document.getElementById('JAVA').click();

</script>

<% endif. %></i>

the above can be replaced with the following htmlb code

<htmlb:button id = "JAVA"

onClientClick = "javascript:set_value('<%= gv_bname%>');"

text = "mubutton"/>

<script>

document.getElementById('JAVA').click();

</script>

<i>But still I wonder, whether it's possible to call javascript directly after selecting a row in the tableview.</i>

its possible check the demo application

sbspext_table/tableviewclient.bsp

Raja

Former Member
0 Kudos

Thanks a lot!

JAVASCRIPT was missing in HTMLB-Button

best regards

Answers (0)