AnsweredAssumed Answered

Javascript: how start function after complete load of form?

Question asked by wimv on Oct 26, 2015
Latest reply on Oct 27, 2015 by pfudala

Hi,

 

I have written some script in the settings of a form to select a lookup value in a list based on part of the url.

 

End of url looks like this:

"... %3DE1211321&RootFolder="

 

I'm taking the "E1211321" out of the url and put that as default value in a lookup, in which "E1211321" is one of the items.

 

Here's the script:

 

function referenceinput(){

var url = window.location.href;

var urlLength = url.length;

referenceFromUrl = url.substring(urlLength-20,urlLength-12);

reference = NWF$('#' + varReference +  ' option:contains(' + referenceFromUrl +')');

referenceValue = reference.val();

reference .attr('selected','selected');

NWF$('#' + varReference).parent().find('input').val(referenceValue);

};

 

varReference represents the dropdown (lookup)

 

This code works perfectly well when I call it from a button click. The dropdown indeed selects "E1211321".

 

However I want this function to happen when the user opens the form and all data have been loaded.

 

When I try the following:

 

NWF.FormFiller.Events.RegisterAfterReady(function () {

referenceinput()

});

 

or

 

NWF$(document).ready(function() {

referenceinput()

});

 

...the function starts well but since the lookup hasn't been loaded yet, nothing is selected.

 

How can I make sure the form is loaded completely before starting the function?

Outcomes