Manipulate DataLabel with JavaScript

  • 20 November 2014
  • 3 replies
  • 7 views

Badge

Hi,

 

i created a data label called "actionlabelvalue" on my view. Now i want to maipulate the content of this data label with javascript, when the browser window unloads.

 

I tried the following code without success:

<script type="text/javascript">window.addEventListener("beforeunload", function (e) { $("[title='ActionLabelValue']").text = 'x';});</script>

 

Maybe someone can put me on the right track?

 

Thanks in advance and kind regards,

Christian


3 replies

Badge +5

This may be a given, but all the presteps were done correctly yes? There is an example here.

http://k2shared.com/2014/10/07/how-to-call-jquery-or-javascript-code-in-a-k2-smartform/

Userlevel 3
Badge +10

There's probably a much better way to do this, but here's my hacky solution:

I've noticed that the DOM may return a page loaded status before some SmartForms pages finish loading content.  I've gotten around this by setting a timer and checking if a content field is not null or has content and then manipulating page data.  For example:

function waitForLoad() {
    if (document.getElementById("someElementIDHere").innerHTML != "") {
        setTimeout(waitForLoad, 1000);
    }
    else {
        main();
    }
}


 


function main() {


    //your code here


}


 


waitForLoad();

Badge +1

Hi

 

the presteps described here (http://k2shared.com/2014/10/07/how-to-call-jquery-or-javascript-code-in-a-k2-smartform/) working correctly. Open up am alert is no problem. :-) At the moment I stuck in manipulating the content of a data label.

 

Kind regards,

Christian

Reply