XPages - Run CS javascript on page render

Sorry another one from me.

When you have a button where you attach some CS script, the server runs any SS script contained in the CS code before the new CS code is sent to the page source for the browser:

For example:

The CS code on the button in designer is

var target = ‘#{javascript:getClientId(“field 1”)}’;

And once sent to the browser, the CS code has then become

var target = ‘view:_id1:_id6:field1’;

This is so when the CS code runs on the users browser everything will continue to work with the id changes that occur when the user connects.

This is fine, but is there anyway you can have some CS code (which also contains SS code just like the above example) that will run on pageload (or post render) and behave in the same fashion where the SS code is run first before being sent to the page source in the browser?

Thanks again for any ideas.

Subject: Found the answer!

Finally found an answer to what I needed to do. In case someone else needs to do it, here’s what I did:-

Make a computed field on the Xpage which will build a string of my CS javascript code, with the appropriate SS code being generated

i.e.

<xp:text escape=“false” id=“computedCode”>

<xp:this.value>

	<![CDATA[#{javascript:var out="<script language=\"Javascript\">\n";

		out = "var source = \"" + getClientId("ELEMENTID") + "\";\n";

		out += "function test(){alert(source)}

		out += "</script>";

		out}]]>

</xp:this.value>

</xp:text>

Then use XSP.addonload to call this CS code calles ‘test()’.

<script type="text/javascript">

	XSP.addOnLoad(function () { test(); }); 

</script>

Hope that all makes sense, it’s been a long day!

:slight_smile: