locked
OnChange event not Firing RRS feed

  • Question



  • Hi,

    I have a bit field with some JavaScript on the OnChange event that is not always firing.

    My code is this:

    alert ("test");

    if(crmForm.all.new_aplicariva.DataValue == 0)

    {

    crmForm.all.new_iva.DataValue = 0;

    crmForm.all.tax.DataValue = 0;

    }

    if(crmForm.all.new_aplicariva.DataValue == 1)

    {

    crmForm.all.productid.FireOnChange();

    }

    This is used to set on an invoice line if the product has a tax or not. If the field is set to NO the two custom fields must be 0.

    I place an alert as the first line of my code but I can´t see the alert message all the times. If I open the record and make any change on a description for example then Save the record and try again the alert is fired, but If I just open the record and changes the value of the bit field nothing happens.

    I tried to set the focus on other field but the problem isn´t solved.


    Jessica
    Wednesday, April 15, 2009 10:14 AM

Answers


  • Hi Morten,

    Thanks for your tips you are right about the code.

    I didn't solve the problem involving the onChange event, I just change de input type from radio button to a drop down list, now the event is always triggered. I suppose that there is a bug on radio button component.

    Does anyone know if there is a hot fix for this problem?
    Jessica
    Thursday, April 16, 2009 10:33 AM

All replies

  • Hi,
    Here one of the solution would be to check if there is any JavaScript error within the form. Try debugging by disabling OnSave event's javascript or something on the same line.

    Regards,
    Nishant Rana
    http://nishantrana.wordpress.com
    Wednesday, April 15, 2009 10:35 AM
  • It has been an issue with check box, the results seems to be better with radio buttons; what are you running; if not running radio buttons; counld you check that?

    Also; you should use true and false, instead of 0 and 1.

    Morten
    Wednesday, April 15, 2009 10:39 AM
  • Hi,

    I´m using a radio buttons for that bit field.

    I got your suggestion and change the 0 and 1 for true or false;

    At this moment on my pc works so I ask the user to tried too.




    Jessica
    Wednesday, April 15, 2009 11:55 AM
  • HI
    Try a picklist
    Had the same problem when selecting a number value to change datetime fields
    Below is the code I used for changing my sla datetime field with a value form a picklist, works like a bomb!!!

      if (crmForm.all.new_sla.SelectedText != "")

    {

      var dt = crmForm.all.new_slatarget.DataValue;

      var hrs = crmForm.all.new_sla.SelectedText;

      currHrs = dt.getHours();

      if ((parseInt(currHrs) + parseInt(hrs)) > 17)

      {

        var tomoroHrs = 8 + ((parseInt(currHrs) + parseInt(hrs)) - 17);

        var tomoroDate =  new Date(dt.setDate(dt.getDate() + 1));

        var newDt = new Date(tomoroDate.setHours(tomoroHrs));

        dt = newDt;

        var dayAfterHrs = (8 + ((parseInt(currHrs) + parseInt(hrs)) - 17)) - 17;

        if (dayAfterHrs > 0)

        {

          var dayAfterDate = new Date(dt.setDate(dt.getDate() + 1));

          var dayAfterDt = new Date(dayAfterDate.setHours(dayAfterHrs));

          dt = dayAfterDt;

            }

      }

                     else

      {

                    dt.setHours(parseInt(currHrs) + parseInt(hrs));

      }

                     crmForm.all.new_slatarget.DataValue = dt;

    }



    Tiaan van Niekerk http://crmdelacreme.blogspot.com Skype:tiaan.van.niekerk1
    Wednesday, April 15, 2009 12:56 PM
  • Hi,

    You shhould also protect your code with checking if DataValue is null. i.e. (see text in bold).

    Typically you would get NULL value; if this field has been registered after you have entered/imported data; the existing records will the have NULL value; and you would need to manage that situation (should do that always..).


    if (crmForm.all.new_aplicariva.DataValue != null)
    {
    if(crmForm.all.new_aplicariva.DataValue == 0)

    {

    crmForm.all.new_iva.DataValue = 0;

    crmForm.all.tax.DataValue = 0;

    }

    if(crmForm.all.new_aplicariva.DataValue == 1)

    {

    crmForm.all.productid.FireOnChange();

    }}




    Thursday, April 16, 2009 8:34 AM

  • Hi Morten,

    Thanks for your tips you are right about the code.

    I didn't solve the problem involving the onChange event, I just change de input type from radio button to a drop down list, now the event is always triggered. I suppose that there is a bug on radio button component.

    Does anyone know if there is a hot fix for this problem?
    Jessica
    Thursday, April 16, 2009 10:33 AM
  • Hi,

    Just to be 100% sure that it's nothing wrong with your code, could you remove your code and just have

    alert ("test");

    on the change event ... and verify that it does not trigger on every change...?

    Morten




    Thursday, April 16, 2009 10:43 AM
  • I actually try that and if a have the radio buttons the onchange event wasn´t triggering always. The alert was just shown in some cases.

    After I change the radio buttons to List box the event was always triggered.


    Jessica
    Thursday, April 16, 2009 10:51 AM
  • Hi,

    .... then It's just to start crawling the KB; to see if you can find anything there.

    Sorry.

    Morten
    Thursday, April 16, 2009 10:57 AM