Skip to Content
avatar image
Former Member

OnChange Event for inputField

Hi,

I have an unique requirement. I have 3 inputFields Length, Width and Depth. I have one more inputField called Amount which is calculated by LWD at runtime.

I want to calculate each time when any of the values in

Length, Width and Depth inputFields changes something like onChange Event.

I know i can calculate it when i click an button.But i don't want to do that.

Is there any way to handle this onChange Event handler?

Thanks in advance

arun

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 18, 2004 at 12:38 AM

    Hi experts,

    I don't understand how to handle this with your code. Le me post the code,

    <%@page language="abap" %>

    <%@extension name="htmlb" prefix="htmlb" %>

    <%@extension name="bsp" prefix="bsp" %>

    <htmlb:content design="design2003" >

    <htmlb:page title="Equipment List " >

    <htmlb:form>

    <%

    data tmp_string type string.

    tmp_string = `<input onChange="javascript:youJsfunction();"`.

    %>

    <htmlb:inputField id = "Field1"

    value = "2"

    alignment = "left" />

    <htmlb:inputField id = "Field2"

    value = "2"

    alignment = "left" />

    <bsp:findAndReplace find = "<input"

    replace = "<%= tmp_string %>" >

    <htmlb:inputField id = "Field3"

    value = "4"

    alignment = "left" />

    </bsp:findAndReplace>

    </htmlb:form>

    </htmlb:page>

    </htmlb:content>

    I have Field1 and Field2, when the value in any of the inputfield changes the Field3 shoulb be calculated with Field1-value+Field2-value.

    How to handle this situation?

    Thanks in advance

    arun

    Add comment
    10|10000 characters needed characters exceeded

    • <%
      data tmp_string type string.
      tmp_string = `<input onChange="javascript:<b>yourJsfunction()</b>;"`.
      %>
      <bsp:findAndReplace find = "<input"
      replace = "<%= tmp_string %>" >
      
      <htmlb:inputField id = "Field1"
      value = "2"
      alignment = "left" />
      </bsp:findAndReplace>
      <bsp:findAndReplace find = "<input"
      replace = "<%= tmp_string %>" >
      
      <htmlb:inputField id = "Field2"
      value = "2"
      alignment = "left" />
      </bsp:findAndReplace>
      <htmlb:inputField id = "Field3"
      value = "4"
      alignment = "left" />
      
      

      <u><b>yourJsfunction</b></u> is a javascript function which you have to write to read field value 1 and fidld value 2 and populate third field.

      Here is a js sample. (note the code is not tested)

      <script>

      function yourJsfunction(){

      document.<your form name>.<input field name3>.value =

      document.<your form name>.<input field name1>.value +

      document.<your form name>.<input field name2>.value ;

      }

      </script>

      Regards

      Raja

  • avatar image
    Former Member
    Dec 11, 2004 at 12:49 AM

    check out onClientClick you can activate Javascript there.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Brian McKellar

      hi brian

      > Excellent.

      I'm glad you like it.

      > In this forum there is a thread about all weblogs. We

      > welcome you to add your writings on it (even if they

      > should point off site).

      I only understood this remark after reading your post again. 😊

      So I'll publish both articles in the said thread as soon as they are finished.

      regards

      nicola

  • avatar image
    Former Member
    Dec 13, 2004 at 02:08 AM

    Hi Craig,

    Can you post some code for "onClientClick you can activate Javascript".

    <htmlb:Inputfield doesn't have onClientClick event. How can we handle Onchange event?

    Thanks in advance

    arun

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 20, 2004 at 06:34 PM

    Hi Durairaj,

    I thought that once i change the value in inputfield it will fire the javascript function. But the onChange event in the function is fired only when i change the value and click in any other inputfield or page.

    Can we implement onChange or custom event like (onArun) for any component in htmlb.

    This is what the code i created to test it,

    <%@page language="abap" %>

    <%@extension name="htmlb" prefix="htmlb" %>

    <%@extension name="bsp" prefix="bsp" %>

    <script>

    function MULTIPLY(){

    document.wdr.MULT.value =

    document.wdr.Field1.value *

    document.wdr.Field2.value *

    document.wdr.Field3.value ;

    }

    </script>

    <%

    data tmp_string type string.

    tmp_string = `<input onChange="javascript:MULTIPLY();"`.

    %>

    <htmlb:content design="design2003" >

    <htmlb:page title="On Change Event Checker " >

    <htmlb:form id="wdr" >

    <bsp:findAndReplace find = "<input"

    replace = "<%= tmp_string %>" >

    <htmlb:inputField id = "Field1"

    value = "0"

    alignment = "left" />

    <br>

    <htmlb:inputField id = "Field2"

    value = "2"

    alignment = "left"

    disabled = "true"/>

    <br>

    <htmlb:inputField id = "Field3"

    value = "2"

    alignment = "left"

    disabled = "true"/>

    <br>

    <htmlb:inputField id = "MULT"

    value = "0"

    alignment = "left"

    disabled = "true"/>

    </bsp:findAndReplace>

    </htmlb:form>

    </htmlb:page>

    </htmlb:content>

    Thanks a lot

    arun

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 01, 2005 at 02:18 PM

    hi all

    I just finished my second article on this subject. The first covers the issue using on JSP and EP 6.0:

    http://variant.ch/phpwiki/WikiBlog/2005-01-31

    the second article shows how to deal with the problem using BSP on SAP R/3 WAS:

    http://variant.ch/phpwiki/WikiBlog/2005-02-01

    I hope this helps anyone.

    regards

    nicola

    ps: sorry for the cross posting. I'll get a SDN blog and you'll escape my babble... 😊

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Maximilian Schaufler

      It's also a nice feeling inside the company especially when someone goes looking for something for SAP and finds one of my blogs here on SDN, they come down to my office and start asking me all sorts of questions - it's great - the T-Shirt is behind my desk 😊

  • avatar image
    Former Member
    Feb 02, 2005 at 05:12 AM

    Try to create a new BSP Extension of inputfield and add the html tag property of onChange ..,, Write JS code to calculate the same.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Maximilian Schaufler

      Has somebody gotten any of this to work with

      <phtmlb:formLayoutInputField

      I'm in doing this in a view (subcontroller) so I have to append the name of the controller to the id??

      Message was edited by: Craig Cmehil

      Ok the only thing that worked for me was the example from Thilo.

      <i>

      In MS Internet Explorer you can use the "named script" like this:

      </i>

      <htmlb:inputField id   = "Inp123"                 
                       value = "//model/edit_wa.pvo_ad_1"/>
      <script for="Inp123" event=onchange type="text/javascript">  
      YourJavaScriptFunc( this );
      </script>
      

      <i>

      Don't know if this works in other browsers too.

      Thilo

      </i>