cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger Javascript

Former Member
0 Kudos

Hello Experts,

I have some fields on the view corresponding to a value node. One of the fields is Phone number. When the user enters the phone number and moves to next field, I want to trigger a JavaScript function that formats the phone number.

I tired like this:

<script for="//CONTEXTNODE/ATTRIBUTE" event=onblur type="text/javascript" >

function()

{

-- code;

}

</script>

But, it's not getting triggered. Can someone please help me with this?

Thank you.

-Ezhno.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Any solution?!

Former Member
0 Kudos

Hi Maren,

Below code will work for your field with java script.

   <%@page language="abap" %>
<%@extension name="thtmlb" prefix="thtmlb" %>
<%@extension name="chtmlb" prefix="chtmlb" %>
<%@extension name="bsp" prefix="bsp" %>

<%

data: lv_Attr_name type string.

lv_attr_name = CONTEXT NODE NAME->IF_BSP_MODEL_BINDING~GET_ATTRIBUTE_NAME( attribute_path = 'ATTRIBUTE NAME').

%>


<script for="<%=lv_attr_name%>" event=onblur type="text/javascript" >
  alert('Java Script Triggered');
</script>

<chtmlb:config mode = "RUNTIME"
               xml  = "<%= controller->configuration_descr->get_config_data( ) %>" />

Regards,

Naresh

Former Member
0 Kudos

Hi Naresh,

Perfect!!

My mistake was the way I referred to the attribute name...

Thank you for your code.

-Ezhno.

Answers (1)

Answers (1)

former_member193634
Active Participant
0 Kudos

Hello,

Do the standard formatting for phone number is not sufficient for your needs (based on country of address if I remember well) ?

If not, using javascript to reformat user entries does not seem the best way to go.

I'd rather try one of the following methods of the view you are using : DO_VALIDATE_INPUT or DO_FINISH_INPUT.

Best regards,

Sylvain AGUETTAZ