Loading...

RE: Calling JavaScript from body of qListView custom display

RE: Calling JavaScript from body of qListView custom display

Home Forums QuickApps Forum Calling JavaScript from body of qListView custom display RE: Calling JavaScript from body of qListView custom display

#5360
Anonymous
Anonymous
Participant

Have you tried something like the following?

<script>if (<%IntField%> > 10) document.write("<span color=red>" + <%IntField%> + "</span>")</script>

However I would recommend NOT using Custom Display tab in this case. We should have example of using Content Editor Web Part or Html Form Web Part to sneak in some Javascript function that you can use with Display Field -> Custom Field -> Calculated Format attribute to render the field with some simple logic.

Basically you put the following script in the OOTB HTML Form Web Part (by using the Source Editor and replace the whole default text).

<script language="text/javascript">

function FormatNumber(num) {   

  if (num.Length == 0) return ' ';   

    

  var iNum = parseFloat(num);

  if (iNum < 0.5) {

       return '<font color="red">' + num + '</font>';   

  } else {

       return '<font color="green">' + num + '</font>';   

  }

}

</script>

Then you add a Custom Field to your list view, and specify Calculated Format as following:

<script>FormatNumber('<%YourColumnName%>');</script>

And you should be done.