locked
Javascript Function RRS feed

  • Question

  • Hi,

    I have a function written in Javascript onLoad event of form. Can i call the function by onChange event of fields?

    Wednesday, April 21, 2010 5:35 PM

Answers

All replies

  • Sure thing. There is no reason that you cannot do that. 
    Daniel Cai | http://danielcai.blogspot.com
    Wednesday, April 21, 2010 5:42 PM
  • It's been a long time since I tried it, but my memory tells me there is no supported solution to global or document scope.  But try it!  It can only fail.

    Now, there are unsupported solutions where you put the functions into a global js file.

    Wednesday, April 21, 2010 5:44 PM
  • Yes you can definitely do so. There should not be any problem unless the function is a global one and not within the scope of the OnLoad function. or you can do is in the onload try creating the function as follows

    var test = function()

    {

    }

     

    call the test() from onload and onchange.

    I would also suggest to move the function to a common js file append the js to your page onload and run the function from where ever required. 

    Wednesday, April 21, 2010 5:52 PM
  • I tried defining a function OnLoad and calling it onChange. It doesn't work. If i use external .js file and include in head section onLoad, i can able to call function from onChange, but i think outlook users will have problem if i use external file.
    Wednesday, April 21, 2010 6:17 PM
  • What if you attach to the field's onchange event from onload instead of using the CRM onchange.

    function test()

    {

    }

     

    crmForm.all.fieldname.attachEvent("onchange", test);


    Blake Scarlavai - Sonoma Partners - http://www.sonomapartners.com/
    Wednesday, April 21, 2010 6:26 PM
  • I dont think the outlook users will have any issue. The js file will be copied to the users machine if it is capable of going offline. Else when online then the js will be embeded in the CRM form they try to access from the the outlook client.

    Wednesday, April 21, 2010 6:26 PM
  • Neerav,

    If it's an external javascript file it will not be automatically copied when going offline.  The user would have to manually deploy to the offline client.  Keeping the javascript in the form customizations would probably be the best way to go.


    Blake Scarlavai - Sonoma Partners - http://www.sonomapartners.com/
    Wednesday, April 21, 2010 6:30 PM
  • Blake,

    Thanks for correcting me.

    In that case i feel the javascript on the form also will need to be manually deployed to the offline client.

    Thanks

    Neerav.

    Wednesday, April 21, 2010 6:45 PM
  • You may try to write your function in this way in the form's onload event: 

    testFunc = function ()
    {
    
    }
    I assure you that you can make call to testFunc() in your field's onchange event. 


    Daniel Cai | http://danielcai.blogspot.com
    Wednesday, April 21, 2010 6:46 PM